We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4ad8df0 commit 542f342Copy full SHA for 542f342
LinkedList/SinglyLinkedList.java
@@ -271,6 +271,27 @@ private boolean detectLoop() {
271
return false;
272
}
273
274
+ // returns node where cycle begins
275
+ private ListNode detectCycleNode() {
276
+ ListNode fast = head;
277
+ ListNode slow = head;
278
+
279
+ while(fast != null && fast.next != null) {
280
281
+ fast = fast.next.next;
282
+ slow = slow.next;
283
284
+ if(fast == slow) {
285
+ ListNode current = head;
286
+ while(current != slow) {
287
+ current = current.next;
288
289
+ }
290
+ return slow;
291
292
293
+ return null;
294
295
296
static boolean compareLists(ListNode head1, ListNode head2) {
297
0 commit comments