Skip to content

Commit 03d976c

Browse files
Merge pull request DaleStudy#712 from changchanghwang/main
[Arthur] week 2
2 parents c9cedf2 + 4af9171 commit 03d976c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

climbing-stairs/changchanghwang.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

valid-anagram/changchanghwang.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)