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 a4473c8 commit cd9e4f4Copy full SHA for cd9e4f4
linked-list-cycle/hwanmini.js
@@ -0,0 +1,29 @@
1
+// 시간복잡도: O(n)
2
+// 공간복잡도: O(1)
3
+
4
+/**
5
+ * Definition for singly-linked list.
6
+ * function ListNode(val) {
7
+ * this.val = val;
8
+ * this.next = null;
9
+ * }
10
+ */
11
12
13
+ * @param {ListNode} head
14
+ * @return {boolean}
15
16
+var hasCycle = function(head) {
17
+ let fastPointer = head;
18
+ let slowPointer = head;
19
20
+ while (fastPointer && fastPointer.next) {
21
+ slowPointer = slowPointer.next;
22
+ fastPointer = fastPointer.next.next
23
24
+ if (fastPointer === slowPointer) return true
25
26
+ }
27
28
+ return false
29
+};
0 commit comments