File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ํ์ด
2
+ // s์ rune์ key๋ก ๊ฐ์ ์ฒ ์์ ๊ฐฏ์๋ฅผ ๋ด๊ฒํ๊ณ
3
+ // t์ ๋น๊ตํ๋ฉด์ ๊ฐฏ์๋ฅผ ํ๋์ฉ ๊ฐ์ํ๊ฒ ํด์
4
+ // ๋จ์ ์ฒ ์๊ฐ ์๊ฑฐ๋ (s์๋ ์๊ณ , r์๋ ์๋ ์ฒ ์๊ฐ ์๋ ๊ฒฝ์ฐ)
5
+ // ๋ ๊ฐ์๋ ์ฒ ์๊ฐ ์์ผ๋ฉด (s์๋ ์๊ณ , r์๋ง ์๋ ์ฒ ์๊ฐ ์๋ ๊ฒฝ์ฐ) false๊ฐ return ๋๊ฒ ํจ.
6
+
7
+ // TC
8
+ // O(n+n+n) = O(n)
9
+
10
+ // SC
11
+ // s์ ๊ธธ์ด๋งํผ ๋์ด๋๋ map์ผ๋ก ์ธํด O(n)
12
+
13
+ func isAnagram (s string , t string ) bool {
14
+ m := make (map [rune ]int )
15
+ for _ , r := range s {
16
+ m [r ]++
17
+ }
18
+ for _ , r := range t {
19
+ m [r ]--
20
+ }
21
+ for _ , count := range m {
22
+ if count < 0 || count > 0 {
23
+ return false
24
+ }
25
+ }
26
+ return true
27
+ }
You canโt perform that action at this time.
0 commit comments