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.
2 parents bf195e0 + d99662c commit d7e778fCopy full SHA for d7e778f
linked-list-cycle/Lustellz.ts
@@ -0,0 +1,29 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * class ListNode {
4
+ * val: number
5
+ * next: ListNode | null
6
+ * constructor(val?: number, next?: ListNode | null) {
7
+ * this.val = (val===undefined ? 0 : val)
8
+ * this.next = (next===undefined ? null : next)
9
+ * }
10
11
+ */
12
+
13
+// Runtime: 49ms
14
+// Memory: 56.94MB
15
16
+function hasCycle(head: ListNode | null): boolean {
17
+ let fast: ListNode = head;
18
+ let slow: ListNode = head;
19
20
+ while (fast && fast.next) {
21
+ fast = fast.next.next;
22
+ slow = slow!.next;
23
24
+ if (fast === slow) {
25
+ return true;
26
+ }
27
28
+ return false;
29
+}
0 commit comments