Created
July 18, 2021 23:08
-
-
Save wohhie/cc6399d13dbccfdfe85284b4cacc4508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static boolean hasCycle(SinglyLinkedListNode head) { | |
SinglyLinkedListNode first = head; | |
SinglyLinkedListNode second = head; | |
do{ | |
first = first.next; | |
second = second.next; | |
second = second != null ? second.next : null; | |
}while (first != null && second != null && first != second); | |
if (first == second) return true; | |
else return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment