Skip to content

Commit 4a3c5fb

Browse files
authored
Merge pull request #2034 from prgmr99/main
2 parents 760153f + 0beca12 commit 4a3c5fb

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

climbing-stairs/prgmr99.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var climbStairs = function (n) {
6+
const memo = {};
7+
8+
function fibo(num, memo) {
9+
if (num === 1) return 1;
10+
if (num === 2) return 2;
11+
12+
if (memo[num]) {
13+
return memo[num];
14+
}
15+
16+
const result = fibo(num - 1, memo) + fibo(num - 2, memo);
17+
memo[num] = result;
18+
19+
return result;
20+
}
21+
22+
return fibo(n, memo);
23+
};

valid-anagram/prgmr99.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {boolean}
5+
*/
6+
var isAnagram = function (s, t) {
7+
const stringMap = new Map();
8+
9+
if (s.length !== t.length) return false;
10+
11+
for (let i = 0; i < s.length; i++) {
12+
const currentValue = stringMap.get(s[i]);
13+
14+
if (currentValue) {
15+
stringMap.set(s[i], currentValue + 1);
16+
} else {
17+
stringMap.set(s[i], 1);
18+
}
19+
}
20+
21+
for (let i = 0; i < t.length; i++) {
22+
const currentValue = t[i];
23+
const currentValueInStringMap = stringMap.get(currentValue);
24+
25+
if (currentValueInStringMap) {
26+
stringMap.set(currentValue, currentValueInStringMap - 1);
27+
} else {
28+
return false;
29+
}
30+
}
31+
32+
return true;
33+
};

0 commit comments

Comments
 (0)