-
https://leetcode.com/problems/reverse-linked-list/
Reverse Linked List - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
in-place로 재정렬 하는 방법.
1->2->3->4->5 로 정렬이 돼있을 때, while문을 들어가기 전, curr은 1을 가리키고, next는 2를 가리키게 한 뒤 while문에 들어간다.
이후부터는 변수가지고 장난치는 것.
var reverseList = function(head) { let prev; let curr; let next; curr = head; next = head.next; curr.next = null; while(next) { prev = curr; curr = next; next = curr.next; curr.next = prev; } return curr; };
댓글