-
-
Notifications
You must be signed in to change notification settings - Fork 195
[bus710] Week 07 #928
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
[bus710] Week 07 #928
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||||||||||||||||
package hello | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안녕하세요 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문제 풀이를 할 때 테스트를 먼저 작성하는 편인데, 패키지 이름을 짧게 적다보니 이렇게 되었습니다 ㅎㅎ |
||||||||||||||||||||||
|
||||||||||||||||||||||
type ListNode struct { | ||||||||||||||||||||||
Val int | ||||||||||||||||||||||
Next *ListNode | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func reverseList(head *ListNode) *ListNode { | ||||||||||||||||||||||
head2 := &ListNode{} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if head == nil { | ||||||||||||||||||||||
return nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 숏컷 로직이 제일 상단에 위치하는게 좋을 것 같아요
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그리고 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그렇네요, 할당 하기 전에 반환하는게 더 나을 것 같습니다. |
||||||||||||||||||||||
|
||||||||||||||||||||||
for { | ||||||||||||||||||||||
head2.Val = head.Val | ||||||||||||||||||||||
if head.Next == nil { | ||||||||||||||||||||||
break | ||||||||||||||||||||||
} | ||||||||||||||||||||||
head = head.Next | ||||||||||||||||||||||
temp := &ListNode{Next: head2} | ||||||||||||||||||||||
head2 = temp | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return head2 | ||||||||||||||||||||||
} |
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.
반복문 내에서 계속 새로운 ListNode struct instance를 생성하는 것은 공간 복잡도 측면에서 효율적이지 않습니다
포인터만을 이용하는 것을 추천드립니다 :)
제가 제안하는 솔루션 또한 첨부합니다, 정 생각이 안 나시거나 바쁘실 때 참고해주세요 (https://gist.github.com/obzva/c5f726474e844e076270aad523acc39e)