ghostjzf / js-algorithm

js常见算法面试题总结
0 stars 0 forks source link

单链表反转 #9

Open ghostjzf opened 3 years ago

ghostjzf commented 3 years ago
function reverseList(head) {
  let prev = null;
  let curr = head;

  while(curr) {
    const cNext = curr.next;

    curr.next = prev;
    prev = curr;
    curr = cNext;
  }

  return prev;
}