Skip to content

Commit 95b84ad

Browse files
committed
Create 0141-linked-list-cycle.rs
1 parent 5081e0e commit 95b84ad

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

rust/0141-linked-list-cycle.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
pub fn has_cycle(head: *mut ListNode) -> bool {
3+
unsafe {
4+
let mut slow = head;
5+
let mut fast = head;
6+
while !fast.is_null() && !(*fast).next.is_null() {
7+
slow = (*slow).next;
8+
fast = (*(*fast).next).next;
9+
if slow == fast {
10+
return true;
11+
}
12+
}
13+
}
14+
false
15+
}
16+
}

0 commit comments

Comments
 (0)