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