*Reverse Linked List

mac2022-06-30  98

 

题目:

Reverse a singly linked list.

 

代码:看不懂,我已经没救了

 

1 public ListNode reverseList(ListNode head) { 2 if (head == null) return head; 3 ListNode cur = head; 4 ListNode pre = null; 5 while (cur.next != null){ 6 ListNode nextNode = cur.next; 7 cur.next = pre; 8 pre = cur; 9 cur = nextNode; 10 } 11 cur.next = pre; 12 return cur; 13 }

reference:http://blog.welkinlan.com/2015/05/06/reverse-linked-list-leetcode-java/

转载于:https://www.cnblogs.com/hygeia/p/4717784.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)