标签:span problems ble sub next ref bsp tno ever
Reverse a singly linked list.
Subscribe to see which companies asked this question.
1 public ListNode reverseList(ListNode head) { 2 if(head==null) return null; 3 if(head.next==null) return head; 4 ListNode pre = head; 5 ListNode cur = head.next; 6 pre.next = null; 7 ListNode next; 8 while(cur != null){ 9 next = cur.next; 10 cur.next = pre; 11 pre = cur; 12 cur = next; 13 } 14 return pre; 15 }
[LeetCode]206. Reverse Linked List
标签:span problems ble sub next ref bsp tno ever
原文地址:http://www.cnblogs.com/zle1992/p/6815467.html