Linked List Cycle LeetCode solution in Java
1public class Solution {2public boolean hasCycle(ListNode head) {3ListNode fast = head;4ListNode slow = head;5boolean result = false;6while (fast != null && fast.next != null) {7fast = fast.next.next;8slow = slow.next;9if (fast == slow) {10result = true;11break;12}13}14return result;15}16}