Skip to content
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
20 changes: 20 additions & 0 deletions climbing-stairs/Totschka.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://leetcode.com/problems/climbing-stairs/
/**
* @SC `O(1)`
* @TC `O(n)`
*/
function climbStairs(n: number): number {
if (n <= 2) {
return n;
}

let prev1 = 1;
let prev2 = 2;

for (let i = 2; i < n; i++) {
let temp = prev1;
prev1 = prev2;
prev2 = temp + prev2;
}
Comment on lines +11 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

DP를 사용해서 풀이하는 방법을 도전해보셔도 좋을것 같습니다!

return prev2;
}
34 changes: 34 additions & 0 deletions valid-anagram/Totschka.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// https://leetcode.com/problems/valid-anagram/

/**
* @SC `O(N)`
* @TC `O(N)`
*/
namespace use_hashmap {
function isAnagram(s: string, t: string): boolean {
if (s.length !== t.length) {
return false;
}
const counter = {};
for (const char of s) {
counter[char] = (counter[char] || 0) + 1;
}
for (const char of t) {
if (!counter[char]) {
return false;
}
counter[char] = counter[char] - 1;
}
return true;
}
}

/**
* @SC `O(N)`
* @TC `O(Nlog(N))`
*/
namespace naive_approach {
function isAnagram(s: string, t: string): boolean {
return [...s].sort().join('') === [...t].sort().join('');
}
}
Loading