Skip to content

Commit 8cc2f40

Browse files
committed
valid anagram solution
1 parent 1926e43 commit 8cc2f40

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

โ€Žvalid-anagram/Yu-Won.jsโ€Ž

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* ๋ฌธ์ œ: https://leetcode.com/problems/valid-anagram/description/
3+
*
4+
* ์š”๊ตฌ์‚ฌํ•ญ:
5+
* ๋‘๊ฐœ์˜ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์กŒ์„ ๋•Œ ๋‘๊ฐœ์˜ ๋ฌธ์ž์—ด์ด ์• ๋„ˆ๊ทธ๋žจ์ธ์ง€ ํŒ๋‹จํ•ด์„œ boolean ์œผ๋กœ ๋ฆฌํ„ด
6+
*
7+
* * */
8+
9+
const validAnagram = (s, t) => {
10+
if(s.length !== t.length) return false;
11+
12+
let count = {};
13+
14+
for(const sChar of s) {
15+
count[sChar] = (count[sChar] || 0) + 1;
16+
}
17+
18+
for(const tChar of t) {
19+
if(!count[tChar]) return false;
20+
count[tChar]--;
21+
}
22+
23+
return true;
24+
}

0 commit comments

Comments
ย (0)