总结
1,链表找中间节点
ListNode fast = head; ListNode slow = head; while (fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; } if (fast != null) 是奇数 ,前一半比后一般多一 { slow = slow.next; }
2.链表反转
public ListNode reverse(ListNode head) { ListNode pre = null; while (head != null) { ListNode next = head.next; head.next = pre; pre = head; head = next; } return pre; }
浙公网安备 33010602011771号