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 847ee56 commit c1930efCopy full SHA for c1930ef
linked-list-cycle/minji-go.java
@@ -0,0 +1,27 @@
1
+/**
2
+ * <a href="https://leetcode.com/problems/linked-list-cycle/">week9-1. linked-list-cycle</a>
3
+ * <li>Description: Return true if there is a cycle in the linked list. </li>
4
+ * <li>Topics: Hash Table, Linked List, Two Pointers</li>
5
+ * <li>Time Complexity: O(N), Runtime 0ms </li>
6
+ * <li>Space Complexity: O(1), Memory 44.37MB</li>
7
+ */
8
+public class Solution {
9
+ public boolean hasCycle(ListNode head) {
10
+ if (head == null) {
11
+ return false;
12
+ }
13
+
14
+ ListNode slow = head;
15
+ ListNode fast = head.next;
16
17
+ while (slow != fast) {
18
+ if (fast == null || fast.next == null) {
19
20
21
+ slow = slow.next;
22
+ fast = fast.next.next;
23
24
25
+ return true;
26
27
+}
0 commit comments