Skip to content

Commit 65e5f8c

Browse files
authored
Merge pull request #720 from yoonthecoder/main
[yoonthecoder] Week 2
2 parents 5a23c83 + bab1ff4 commit 65e5f8c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

climbing-stairs/yoonthecoder.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function climbStairs(n) {
2+
// if there's only 1 step, return 1
3+
if (n === 1) return 1;
4+
// initialize the first prev values (when n=1 and n=0 each)
5+
let prev1 = 1;
6+
let prev2 = 1;
7+
// iterate through step 2 to n
8+
for (let i = 2; i <= n; i++) {
9+
let current = prev1 + prev2;
10+
prev2 = prev1;
11+
prev1 = current;
12+
}
13+
return prev1;
14+
}
15+
16+
// Time complexity: O(n) - single for loop
17+
// Space Complexity: O(1)

valid-anagram/yoonthecoder.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var isAnagram = function (s, t) {
2+
const sArray = [];
3+
const tArray = [];
4+
5+
for (i = 0; i < s.length; i++) {
6+
sArray.push(s.charAt(i));
7+
}
8+
for (i = 0; i < t.length; i++) {
9+
tArray.push(t.charAt(i));
10+
}
11+
12+
return JSON.stringify(sArray.sort()) === JSON.stringify(tArray.sort());
13+
};
14+
15+
// Time complexity : O(nlogn)
16+
// Space complexity : O(n)

0 commit comments

Comments
 (0)