Created
June 8, 2015 13:50
-
-
Save cangoal/2fc7f680f7a14a66c01a to your computer and use it in GitHub Desktop.
LeetCode - Linked List Cycle
This file contains hidden or 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
| public boolean hasCycle(ListNode head) { | |
| if(head == null) return false; | |
| ListNode runner = head; | |
| ListNode walker = head; | |
| while(runner.next != null && runner.next.next != null){ | |
| runner = runner.next.next; | |
| walker = walker.next; | |
| if(runner == walker){ | |
| return true; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment