-
Notifications
You must be signed in to change notification settings - Fork 328
Open
Description
안녕하세요!
책을 읽다가 헷갈리는 부분이 생겨 질문 드립니다.
p.501의 1번 풀이 중,
cur.next, head.next, head = head, cur.next, head.next
코드중, cur의 구조에 대해 이해가 가지 않아 책의 예제인 head가 4->2->1->3의 ListNode일 때를 구현해보았습니다.
cur의 변화를 print 해보니,
cur: None->4
cur: None->2->4 로 업데이트 되는 것을 확인하였습니다.
하지만 제 생각에는
cur: None->4
(이때 head: 2->1->3)
따라서 cur은 None->2->1->3이라고 생각했는데,
2->4가 어떤 방식으로, 어떻게 연결되는지 모르겠습니다.
감사합니다.
++ 추가: 해결했습니다!!
cur.next, head.next, head = head, cur.next, head.next
첫번째 루프
cur: None->4
head.next: None
head: 2->1->3
두번째 루프
cur.next=head =2->??
head.next=cur.next = 4
head=head.next = 1->3
다중할당이므로 다음과 같은 과정을 거치기 때문이라고 생각합니다!!
Metadata
Metadata
Assignees
Labels
No labels