Skip to content

[Arthur] week 2 #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions climbing-stairs/changchanghwang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Time complexity, O(n)
// Space complexity, O(1)
// 피보나치 수열로 풀이가 가능하다.
func climbStairs(n int) int {
a, b := 1, 1
for ; n > 1; n-- {
a, b = b, a+b
}
return b
}
24 changes: 24 additions & 0 deletions valid-anagram/changchanghwang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Time complexity, O(n)
// Space complexity, O(1)
func isAnagram(s string, t string) bool {
if len(s) != len(t) {
return false
}
count := make([]int, 26)

for index, _ := range count {
count[index] = 0
}

for i := 0; i < len(s); i++ {
count[int(s[i])-int('a')]++ // s의 문자를 카운트하고
count[int(t[i])-int('a')]-- // a의 문자를 -1 한다.
}

for _, val := range count {
if val != 0 { // 0이 아니라면 다른 문자열이 있는것이기 때문에 false
return false
}
}
return true
}
Loading