Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[yoonthecoder] Week 2 #720

Merged
merged 2 commits into from
Dec 22, 2024
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