Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions climbing-stairs/eunice-hong.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function climbStairs(n: number): number {
// memoization to store the results of the subproblems
const memo = new Map();

// if n is 1 or 2, return n
memo.set(1, 1);
memo.set(2, 2);

// recursive function to calculate the number of ways to climb the stairs
function climb(n: number, memo: Map<number, number>): number {
let result = memo.get(n);
if (result) {
return result;
} else {
result = climb(n - 1, memo) + climb(n - 2, memo);
memo.set(n, result);
return result;
}
}

return climb(n, memo);
}
22 changes: 22 additions & 0 deletions valid-anagram/eunice-hong.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function isAnagram(s: string, t: string): boolean {
// if the length of the two strings are not the same, return false
if (s.length !== t.length) return false;

// create a map of the characters in string s and t
const sMap = new Map();
const tMap = new Map();

// iterate through the strings and add the characters to the maps
for (let i = 0; i < s.length; i++) {
sMap.set(s[i], (sMap.get(s[i]) ?? 0) + 1);
tMap.set(t[i], (tMap.get(t[i]) ?? 0) + 1);
}

// if the values of the maps are not the same, return false
for (let char of sMap.keys()) {
if (sMap.get(char) !== tMap.get(char)) {
return false;
}
}
return true;
}