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
20 changes: 20 additions & 0 deletions climbing-stairs/Grit03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @param {number} n
* @return {number}
*/
var climbStairs = function (n) {
const dp = [0];

for (let i = 1; i <= n; i++) {
if (i === 1) {
dp[1] = 1;
continue;
}
if (i === 2) {
dp[2] = 2;
continue;
}
dp[i] = dp[i - 2] + dp[i - 1];
}
return dp[n];
};
28 changes: 28 additions & 0 deletions valid-anagram/Grit03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isAnagram = function (s, t) {
const sMap = new Map();
const tMap = new Map();
for (const str of [...s]) {
sMap.set(str, (sMap.get(str) ?? 0) + 1);
}

for (const str of [...t]) {
tMap.set(str, (tMap.get(str) ?? 0) + 1);
}
Comment on lines +7 to +15
Copy link
Member

@hyunjung-choi hyunjung-choi Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개선: Map 1개 사용

const charCount = {};

for (const char of s) {
  charCount[char] = (charCount[char] ?? 0) + 1;
}

for (const char of t) {
  charCount[char] = (charCount[char] ?? 0) - 1;
}

이렇게 Map 한 개로도 충분히 풀 수 있습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다! :)


if (sMap.size === tMap.size) {
let answer = true;
for (let [str, count] of sMap) {
if (!tMap.get(str) || tMap.get(str) !== sMap.get(str)) {
answer = false;
}
}
return answer;
}

return false;
};