Skip to content
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
34 changes: 34 additions & 0 deletions climbing-stairs/youngDaLee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package youngDaLee

func climbStairs(n int) int {
if n <= 2 {
return n
}

dp := make([]int, n+1)
dp[1] = 1
dp[2] = 2

for i := 3; i <= n; i++ {
dp[i] = dp[i-1] + dp[i-2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dp[i]를 구할 때마다 dp[i-1]dp[i-2]만 필요하므로 O(n) space의 DP 리스트가 아닌 O(1) space의 변수 두 개만 사용함으로써 공간 복잡도를 최적화 할 수 있을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 넵 감사합니다!!
문제 주차 관련해서도 다음 주 부터는 주의하겠습니다 m(_ _)m

}
return dp[n]
}

/*
Limit Exceeded
func climbStairs(n int) int {
return dfs(0, n)
}

func dfs(now, n int) int {
if now > n {
return 0
}
if now == n {
return 1
}

return dfs(now+1, n) + dfs(now+2, n)
}
*/
21 changes: 21 additions & 0 deletions product-of-array-except-self/youngDaLee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package youngDaLee

func productExceptSelf(nums []int) []int {
n := len(nums)
result := make([]int, n)

// Calculate left products
leftProduct := 1
for i := 0; i < n; i++ {
result[i] = leftProduct
leftProduct *= nums[i]
}

// Calculate right products and combine with left products
rightProduct := 1
for i := n - 1; i >= 0; i-- {
result[i] *= rightProduct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명도 직관적이고 코드도 깔끔하네요 ><

rightProduct *= nums[i]
}
return result
}
44 changes: 44 additions & 0 deletions valid-anagram/youngDaLee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package youngDaLee

import "strings"

func isAnagram(s string, t string) bool {
if len(s) != len(t) {
return false
}

if s == t {
return true
}

sDict := make(map[string]int)
sList := strings.Split(s, "")
for _, data := range sList {
if num, ok := sDict[data]; ok {
sDict[data] = num + 1
} else {
sDict[data] = 1
}
}

tList := strings.Split(t, "")
for _, data := range tList {
if num, ok := sDict[data]; ok {
sDict[data] = num - 1
} else {
return false
}

if sDict[data] < 0 {
return false
}
}

for _, num := range sDict {
if num != 0 {
return false
}
}

return true
}