查找链表的中点
public ListNode middleNode(ListNode head) {
ListNode slow = head;
ListNode fast = head;
while (fast.next != null && fast.next.next != null) {
slow = slow.next;
fast = fast.next.next;
}
return slow;
}
合并链表
public void merge(ListNode l1,ListNode l2){
while(l1!=null&&l2!=null){
ListNode q1 = l1.next;
ListNode q2 = l2.next;
l1.next = l2;
l2.next = q1;
l1 = q1;
l2 = q2;
}
}
反转链表
public ListNode reverse(ListNode head){
ListNode prev = null;
ListNode cur = head;
while(cur!=null){
ListNode next = cur.next;
cur.next = prev;
prev = cur;
cur = next;
}
return prev;
}