Leetcode 206: 反转链表

题目描述:

反转一个单链表。

示例:

输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL

深信服面试。。。。原题

var reverseList = function(head) {
   let cur = head;
   let prev = null;
   while(cur !== null) {
       let temp = cur.next;
       cur.next = prev;
       prev = cur;
       cur = temp;
   }
    return prev;
}

 

你可能感兴趣的:(Javascript,Leetcode,leetcode,206,反转单链表,js)