(Node head)
| 95 | } |
| 96 | |
| 97 | public static boolean detectLoop(Node head){ |
| 98 | Node hare = head.next; |
| 99 | Node tortoise = head; |
| 100 | while( hare != tortoise ) |
| 101 | { |
| 102 | if(hare==null || hare.next==null) return false; |
| 103 | hare = hare.next.next; |
| 104 | tortoise = tortoise.next; |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | public static int length(Node head){ |
| 110 | int ret=0; |