diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index a7cff2614..440ed01a5 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -2,12 +2,10 @@ name: Integration 🔄 on: pull_request: - merge_group: jobs: linelint: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' steps: - uses: actions/checkout@v4 with: diff --git a/linked-list-cycle/DaleSeo.rs b/linked-list-cycle/DaleSeo.rs new file mode 100644 index 000000000..bd88e1f4b --- /dev/null +++ b/linked-list-cycle/DaleSeo.rs @@ -0,0 +1,28 @@ +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +// TC: O(n) +// SC: O(1) +impl Solution { + pub fn has_cycle(head: Option>) -> bool { + let mut slow = &head; + let mut fast = &head; + + while fast.is_some() && fast.as_ref().unwrap().next.is_some() { + slow = &slow.as_ref().unwrap().next; + fast = &fast.as_ref().unwrap().next.as_ref().unwrap().next; + + if slow.as_ref().map(|node| node.as_ref() as *const _) + == fast.as_ref().map(|node| node.as_ref() as *const _) + { + return true; + } + } + + false + } +}