Skip to content

Commit ce6d852

Browse files
committed
Time: 186 ms (19.55%), Space: 38.7 MB (88.49%) - LeetHub
1 parent 74d9149 commit ce6d852

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Example:
3+
* var li = ListNode(5)
4+
* var v = li.`val`
5+
* Definition for singly-linked list.
6+
* class ListNode(var `val`: Int) {
7+
* var next: ListNode? = null
8+
* }
9+
*/
10+
11+
class Solution {
12+
fun hasCycle(head: ListNode?): Boolean {
13+
var slow = head
14+
var fast = head?.next
15+
while(fast != null && fast?.next != null){
16+
if(slow == fast) return true
17+
slow = slow?.next
18+
fast = fast?.next?.next
19+
}
20+
return false
21+
}
22+
}

0 commit comments

Comments
 (0)