-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #758 from nakjun12/main
[nakjun12] Week 2
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
for (let i = 3; i <= n; i++) { | ||
dp[i] = dp[i - 1] + dp[i - 2]; | ||
} | ||
return dp[n]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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; | ||
} |