Skip to content
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

[똘치] Week 3 #771

Merged
merged 3 commits into from
Dec 29, 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
20 changes: 20 additions & 0 deletions reverse-bits/easyone-jwlee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 풀이
// result 가장 오른쪽 값에 num의 값을 추가하면서 왼쪽으로 밀어 reverse 처리.

// TC
// for문은 무조건 32회만 돌기때문에 O(1)

// SC
// 추가적인 공간 사용량은 일정하므로 0(1)

func reverseBits(num uint32) uint32 {
result := uint32(0)
for i := 0; i < 32; i++ {
result <<= 1
if num%2 == 1 {
result++
}
num >>= 1
}
return result
}
20 changes: 20 additions & 0 deletions two-sum/easyone-jwlee.go
Copy link
Member

Choose a reason for hiding this comment

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

안녕하세요
go코드를 처음 보는데 문법이 재미있네요
잘 부탁드립니다:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

안녕하세요
go도 파이썬만큼은 아니지만 처음 시작하기에는 러닝커브도 길지 않고 할 수록 참 재밌는 언어예요
나중에 한번 go도 즐겨보세요^ㅡ^
반갑습니다^ㅡ^

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 풀이
// map의 key에 값, value에 index를 넣어, target-num이 map에 존재할 때를 찾기.
// 오직 하나의 답만 무조건 존재한다고 했기 때문에 찾자마자 return.

// TC
// 가장 마지막 인덱스까지 가서야 값을 구할 수 있었다고 하면, nums의 길이만큼 for문을 한바퀴 돌기때문에 O(n).

// SC
// 중복없이 마지막 인덱스까지 가서 값을 구한다면 들어오는 nums의 길이만큼 map도 공간을 차지하게 되므로 O(n).

func twoSum(nums []int, target int) []int {
m := make(map[int]int)
for i, num := range nums {
if index, ok := m[target-num]; ok {
return []int{index, i}
}
m[num] = i
}
return []int{0, 0}
}
Loading