-
Notifications
You must be signed in to change notification settings - Fork 126
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
[YeomChaeeun] Week 7 #930
[YeomChaeeun] Week 7 #930
Conversation
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.
안녕하세요, @YeomChaeeun 님! 코드 공유해주셔서 감사드립니다. 아직 푸시는 중으로 파악되는데 현재까지 진행해주신 커밋에 대해서 몇 가지 코멘트를 남겨보았어요!
} | ||
|
||
// 마지막 노드에 도달할 때까지 계속 재귀 호출 | ||
const newHead = reverseList(head.next) |
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.
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.
아, 추가로 아래는 제가 위 메모리 비교 테스트에 쓰인 이전에 스택으로 풀었을 때의 코드인데 혹시 필요하실까봐 첨부드려요!
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var reverseList = function(head) {
const stack = []
let temp = head
while (temp){
stack.push(temp.val)
temp = temp.next
}
if (!stack.length){
return null
}
const popped = stack.pop()
const answer = new ListNode(popped)
temp = answer
while (stack.length > 0){
const popped = stack.pop()
temp.next = new ListNode(popped)
temp = temp.next
}
return answer
};
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.
오 좋은 방법 알려주셔서 감사합니다! 😊
const newHead = reverseList(head.next) | ||
|
||
// 백트래킹 과정 | ||
head.next.next = head |
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.
개인적으로 이 부분이 코드를 읽을 때 직관적이다라는 생각이 들지 않았습니다. 얼핏 읽었을 때 "head 의 다음의 다음 노드가 다시 head?" 인데 확 와닿지는 않더라구요. 그렇다고 재귀로 풀었을 때 더 나은 방법이 있나 생각해보면 또 다른 방법은 잘 떠오르진 않네요!
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.
앞뒤를 바꿔주는 작업이라고 생각하면 될거같아요 ^^
저도 여러 그림을 그려가며 백트래킹으로 풀어나갔던 것인데 stack도 한번 시도해보겠습니다
감사합니다 👍
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.