<Prove safety offer> 13 title

topic:

After the head node is defined a function, a list of input, output and inverting the inverted list of list head node

Ideas:

(1) stored at a current node

(2) points to the next reversal of the current node, a node point

(3) updating the current node pre

(4) the current node to the next node

Code:

public class Thirdteenth {
class ListNode{
ListNode next;
int val;
}
public static ListNode reverseList(ListNode head){
if (head == null){
return null;
}
ListNode cur = head;
ListNode pre = null;
while(cur != null){
ListNode temp = cur.next;
cur.next = pre;
pre = cur;
cur = temp;
}
return pre;
}
}

 

Guess you like

Origin www.cnblogs.com/HarSong13/p/11327550.html