File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ // Time complexity, O(n)
2+ // Space complexity, O(1)
3+ // ํผ๋ณด๋์น ์์ด๋ก ํ์ด๊ฐ ๊ฐ๋ฅํ๋ค.
4+ func climbStairs (n int ) int {
5+ a , b := 1 , 1
6+ for ; n > 1 ; n -- {
7+ a , b = b , a + b
8+ }
9+ return b
10+ }
Original file line number Diff line number Diff line change 1+ // Time complexity, O(n)
2+ // Space complexity, O(1)
3+ func isAnagram (s string , t string ) bool {
4+ if len (s ) != len (t ) {
5+ return false
6+ }
7+ count := make ([]int , 26 )
8+
9+ for index , _ := range count {
10+ count [index ] = 0
11+ }
12+
13+ for i := 0 ; i < len (s ); i ++ {
14+ count [int (s [i ])- int ('a' )]++ // s์ ๋ฌธ์๋ฅผ ์นด์ดํธํ๊ณ
15+ count [int (t [i ])- int ('a' )]-- // a์ ๋ฌธ์๋ฅผ -1 ํ๋ค.
16+ }
17+
18+ for _ , val := range count {
19+ if val != 0 { // 0์ด ์๋๋ผ๋ฉด ๋ค๋ฅธ ๋ฌธ์์ด์ด ์๋๊ฒ์ด๊ธฐ ๋๋ฌธ์ false
20+ return false
21+ }
22+ }
23+ return true
24+ }
You canโt perform that action at this time.
0 commit comments