URL: https://leetcode.com/problems/linked-list-cycle/ Signed-off-by: Matej Focko <me@mfocko.xyz>
16 lines
311 B
Kotlin
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
|
|
}
|
|
}
|