Skip to content

Commit d859932

Browse files
jihyun-fastforwardsonjh1217
authored andcommitted
valid anagram
1 parent b0893aa commit d859932

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-anagram/sonjh1217.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
func isAnagram(_ s: String, _ t: String) -> Bool {
3+
var count = [Character:Int]()
4+
for char in s {
5+
count[char, default: 0] += 1
6+
}
7+
8+
for char in t {
9+
count[char, default: 0] -= 1
10+
11+
if count[char]! < 0 {
12+
return false
13+
}
14+
}
15+
16+
return count.values.allSatisfy {$0 == 0}
17+
18+
//시간 복잡도 O(n)
19+
//공간 복잡도 O(n)
20+
}
21+
}
22+

0 commit comments

Comments
 (0)