-
Notifications
You must be signed in to change notification settings - Fork 125
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
[똘치] Week 3 #771
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요
go코드를 처음 보는데 문법이 재미있네요
잘 부탁드립니다:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요
go도 파이썬만큼은 아니지만 처음 시작하기에는 러닝커브도 길지 않고 할 수록 참 재밌는 언어예요
나중에 한번 go도 즐겨보세요^ㅡ^
반갑습니다^ㅡ^