LeetCode/kt/linked-list-cycle.kt
2025-02-08 23:10:33 +01:00

16 lines
311 B
Kotlin

class Solution {
fun hasCycle(head: ListNode?): Boolean {
var (x, y) = head to head
while (y != null && y!!.next != null) {
x = x!!.next
y = y!!.next!!.next
if (x == y) {
return true
}
}
return false
}
}