Skip to content
Closed
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 valid-anagram/soobing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function isAnagram(s: string, t: string): boolean {
const map = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

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

new Map<string,number> 이런식으로 타입을 지정해주어도 좋을거같아요!

for (let i = 0; i < s.length; i++) {
map.set(s[i], (map.get(s[i]) || 0) + 1);
}
for (let i = 0; i < t.length; i++) {
if (!map.has(t[i])) {
return false;
}
const newCount = map.get(t[i]) - 1;
if (newCount < 0) return false;
if (newCount === 0) map.delete(t[i]);
else map.set(t[i], map.get(t[i]) - 1);
}

return map.size === 0;
}