LeetCode-206. Reverse Linked List
2017-06-27 21:26
309 查看
Reverse Linked List
Reverse a singly linked list./** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} head * @return {ListNode} */ var reverseList = function(head) { if(head===null) return null; if(head.next===null) return head; var p=head.next; var q=reverseList(p); head.next=null; p.next=head; return q; };
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} head * @return {ListNode} */ var reverseList = function(head) { if(head===null||head.next===null) return head; var p=head; var q=head.next; p.next=null; var tmp; while(q!==null){ tmp=q.next; q.next=p; p=q; q=tmp; } return p; };
相关文章推荐
- LeetCode-206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- LeetCode:206. Reverse Linked List
- leetcode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- Leetcode 206. Reverse Linked List cpp实现
- [LeetCode]206. Reverse Linked List
- [LeetCode] 206. Reverse Linked List
- [LeetCode]206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- Leetcode:206. Reverse Linked List
- leetCode_Add to List 206. Reverse Linked List
- Leetcode-206. Reverse Linked List
- leetcode 206. Reverse Linked List
- [leetcode] 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- 【leetcode】206. Reverse Linked List
- LeetCode - 206. Reverse Linked List
- Leetcode 206. Reverse Linked List
- 【Leetcode】92. Reverse Linked List II && 206. Reverse Linked List