(Node head, int x)
| 44 | } |
| 45 | |
| 46 | public static void makeLoop(Node head, int x) { |
| 47 | if (x == 0) |
| 48 | return; |
| 49 | Node curr = head; |
| 50 | Node last = head; |
| 51 | |
| 52 | int currentPosition = 1; |
| 53 | while (currentPosition < x) { |
| 54 | curr = curr.next; |
| 55 | currentPosition++; |
| 56 | } |
| 57 | |
| 58 | while (last.next != null) |
| 59 | last = last.next; |
| 60 | last.next = curr; |
| 61 | } |
| 62 | |
| 63 | public static boolean detectLoop(Node head) { |
| 64 | Node hare = head.next; |