Skip to content

[nakjun12] Week 2 #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions climbing-stairs/nakjun12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// T.C: O(n)
// S.C: O(n)

function climbStairs(n: number) {
const dp = { 1: 1, 2: 2 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DP와 Object를 사용하셨는데, 이를 좀 더 생각해보면 Arr로 가능하지 않을까요?

for (let i = 3; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
19 changes: 19 additions & 0 deletions valid-anagram/nakjun12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function isAnagram(s: string, t: string): boolean {
if (s.length !== t.length) return false;

// 공간 복잡도: O(k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 k로 작성해주셨는데, 문제 조건(lowercase English letters)상 아마 이건 상수가 되지 않을까요?

const hash: { [key: string]: number } = {};

// 시간 복잡도: O(n)
for (let char of s) {
hash[char] = (hash[char] || 0) + 1;
}

// 시간 복잡도: O(n)
for (let char of t) {
if (!hash[char]) return false;
hash[char]--;
}

return true;
}
Loading