Skip to content

Commit af17640

Browse files
authored
Merge pull request #2061 from DaleSeo/main
[DaleSeo] WEEK 09 solutions
2 parents 77b83f7 + 5d3bf6a commit af17640

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.github/workflows/integration.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ name: Integration 🔄
22

33
on:
44
pull_request:
5-
merge_group:
65

76
jobs:
87
linelint:
98
runs-on: ubuntu-latest
10-
if: github.event_name == 'pull_request'
119
steps:
1210
- uses: actions/checkout@v4
1311
with:

linked-list-cycle/DaleSeo.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Definition for singly-linked list.
2+
#[derive(PartialEq, Eq, Clone, Debug)]
3+
pub struct ListNode {
4+
pub val: i32,
5+
pub next: Option<Box<ListNode>>,
6+
}
7+
8+
// TC: O(n)
9+
// SC: O(1)
10+
impl Solution {
11+
pub fn has_cycle(head: Option<Box<ListNode>>) -> bool {
12+
let mut slow = &head;
13+
let mut fast = &head;
14+
15+
while fast.is_some() && fast.as_ref().unwrap().next.is_some() {
16+
slow = &slow.as_ref().unwrap().next;
17+
fast = &fast.as_ref().unwrap().next.as_ref().unwrap().next;
18+
19+
if slow.as_ref().map(|node| node.as_ref() as *const _)
20+
== fast.as_ref().map(|node| node.as_ref() as *const _)
21+
{
22+
return true;
23+
}
24+
}
25+
26+
false
27+
}
28+
}

0 commit comments

Comments
 (0)