@@ -0,0 +1,1332 @@
+/**%0A *%09Given a linked list, determine if it has a cycle in it.%0A *%09%0A *%09Author: matao%0A */%0A%0Aclass ListNode %7B%0A%09int val;%0A%09ListNode next;%0A%09ListNode(int x) %7B%0A%09%09val = x;%0A%09%09next = null;%0A%09%7D%0A%7D%0A%0Apublic class LinkedListCycle %7B%0A%09public static boolean hasCycle(ListNode head) %7B%0A        if(head == null) %7B%0A            return false;%0A        %7D%0A        ListNode slow = head;%0A        ListNode fast = head;%0A        while(fast.next != null && fast.next.next != null) %7B%0A            slow = slow.next;%0A            fast = fast.next.next;%0A            if(slow == fast)%0A                return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09// null%0A%09%09ListNode head1 = null;%0A%09%09System.out.println(hasCycle(head1) + %22%22);%0A%0A%09%09// 1-%3Enull%0A%09%09ListNode head2 = new ListNode(1);%0A%09%09System.out.println(hasCycle(head2) + %22%22);%0A%0A%09%09// 1-%3E2-%3Enull%0A%09%09ListNode head3 = new ListNode(1);%0A%09%09ListNode node1 = new ListNode(2);%0A%09%09head3.next = node1;%0A%09%09System.out.println(hasCycle(head3) + %22%22);%0A%0A%09%09// 1-%3E2-%3E3-%3Enull%0A%09%09ListNode head4 = new ListNode(1);%0A%09%09ListNode node2 = new ListNode(3);%0A%09%09head4.next = node1;%0A%09%09node1.next = node2;%0A%09%09System.out.println(hasCycle(head4) + %22%22);%0A%0A%09%09// 1-%3E2-%3E3-%3E2%0A%09%09ListNode head5 = new ListNode(1);%0A%09%09head5.next = node1;%0A%09%09node1.next = node2;%0A%09%09node2.next = node1;%0A%09%09System.out.println(hasCycle(head5) + %22%22);%0A%09%7D%0A%7D

add Linked List Cycle solution