File tree Expand file tree Collapse file tree 1 file changed +13
-17
lines changed Expand file tree Collapse file tree 1 file changed +13
-17
lines changed Original file line number Diff line number Diff line change 1+ //๋ฌธ์์ด s, t๋ฅผ ๋ฐ๊ณ , t๊ฐ s์ ์ ๋๊ทธ๋จ์ด๋ฉด true, ์๋๋ฉด false ์ถ๋ ฅ
2+
13class Solution {
2- func climbStairs( _ n: Int ) -> Int {
3- var result = 0
4+ func isAnagram( _ s: String , _ t: String ) -> Bool {
5+ ///๋์ด ๋ฌธ์ ๊ฐฏ์๊ฐ ๋ค๋ฅด๋ค๋ฉด ๋ฐ๋ก False
6+ if s. count != t. count { return false }
47
5- for i in 0 ... ( n/ 2 ) {
6- if i == 0 {
7- result += 1
8- continue
9- }
10-
11- let x = n - ( 2 * i)
8+ ///ํด์ฌํ
์ด๋ธ ์ฌ์ฉ
9+ var wordDic : [ Character : Int ] = [ : ]
1210
13- result += ncm ( x+ i, i)
11+ ///s์ ๊ธ์๋ค์ 1์ฉ ์ถ๊ฐ, t์ ๊ธ์๋ค์ 1์ฉ ๊ฐ์
12+ for (sChar, tChar) in zip ( s, t) {
13+ wordDic [ sChar, default: 0 ] += 1
14+ wordDic [ tChar, default: 0 ] -= 1
1415 }
1516
16- return result
17- }
18-
19- func ncm( _ n: Int , _ m: Int ) -> Int {
20- if m == 1 { return n }
21- if m == n { return 1 }
22- return ( 1 ... m) . reduce ( 1 ) { $0 * ( $1 + n- m) / $1 }
17+ ///๋์
๋๋ฆฌ์ ๋ชจ๋ ๊ฐ์ด ์์๋์ด 0์ด ๋๋ฉด true
18+ return wordDic. values. allSatisfy { $0 == 0 }
2319 }
2420}
You canโt perform that action at this time.
0 commit comments