diff --git a/climbing-stairs/jthw1005.js b/climbing-stairs/jthw1005.js new file mode 100644 index 0000000000..c4df4152a4 --- /dev/null +++ b/climbing-stairs/jthw1005.js @@ -0,0 +1,13 @@ +function climbStairs(n) { + const memo = {}; + + function dp(k) { + if (k === 1) return 1; + if (k === 2) return 2; + if (memo[k]) return memo[k]; + memo[k] = dp(k - 1) + dp(k - 2); + return memo[k]; + } + + return dp(n); +} diff --git a/valid-anagram/jthw1005.js b/valid-anagram/jthw1005.js new file mode 100644 index 0000000000..3ba2b4a480 --- /dev/null +++ b/valid-anagram/jthw1005.js @@ -0,0 +1,14 @@ +const isAnagram = (s, t) => { + const data = new Array(26).fill(0); + const a_ascii = 'a'.charCodeAt(); + + for (const char of s) { + data[char.charCodeAt() - a_ascii]++; + } + + for (const char of t) { + data[char.charCodeAt() - a_ascii]--; + } + + return !data.some((el) => el !== 0); +};