标签:oid image tor blog link exp close void logs
单链表:
public class ListNode { int val; ListNode next; ListNode (int val) { this.val = val; } }
1、反转单链表
public void reverseLinkedList(ListNode head) { ListNode pre = null; while (head != null) { ListNode next = head.next; head.next = pre; pre = head; head = next; } return pre; }
2、寻找单链表的中点
public ListNode findMid(ListNode head) { ListNode slow = head; ListNode fast = head; while (fast != null && fast.next != null) { fast = fast.next.next; slow = slow.next; } return slow; }
标签:oid image tor blog link exp close void logs
原文地址:http://www.cnblogs.com/zhiyangjava/p/6523481.html