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