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
17 changes: 17 additions & 0 deletions climbing-stairs/yoonthecoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function climbStairs(n) {
// if there's only 1 step, return 1
if (n === 1) return 1;
// initialize the first prev values (when n=1 and n=0 each)
let prev1 = 1;
let prev2 = 1;
// iterate through step 2 to n
for (let i = 2; i <= n; i++) {
let current = prev1 + prev2;
prev2 = prev1;
prev1 = current;
}
return prev1;
}

// Time complexity: O(n) - single for loop
// Space Complexity: O(1)
16 changes: 16 additions & 0 deletions valid-anagram/yoonthecoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var isAnagram = function (s, t) {
const sArray = [];
const tArray = [];

for (i = 0; i < s.length; i++) {
sArray.push(s.charAt(i));
}
for (i = 0; i < t.length; i++) {
tArray.push(t.charAt(i));
}

return JSON.stringify(sArray.sort()) === JSON.stringify(tArray.sort());
};

// Time complexity : O(nlogn)
// Space complexity : O(n)
Loading