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 4dfafee commit 5e2292aCopy full SHA for 5e2292a
linked-list-cycle/mintheon.java
@@ -0,0 +1,28 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * class ListNode {
4
+ * int val;
5
+ * ListNode next;
6
+ * ListNode(int x) {
7
+ * val = x;
8
+ * next = null;
9
+ * }
10
11
+ */
12
+//시간복잡도: O(n)
13
+//공간복잡도: O(1)
14
+public class Solution {
15
+ public boolean hasCycle(ListNode head) {
16
+ ListNode slow = head;
17
+ ListNode fast = head;
18
+
19
+ while(fast != null && fast.next != null) {
20
+ slow = slow.next;
21
+ fast = fast.next.next;
22
23
+ if(slow == fast) return true;
24
+ }
25
26
+ return false;
27
28
+}
0 commit comments