We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 18697e0 commit 9688594Copy full SHA for 9688594
linked-list-cycle/WhiteHyun.swift
@@ -0,0 +1,29 @@
1
+//
2
+// 141. Linked List Cycle.swift
3
+// https://leetcode.com/problems/linked-list-cycle/description/
4
+// Algorithm
5
6
+// Created by 홍승현 on 2024/05/04.
7
8
+
9
+import Foundation
10
11
+final class LeetCode141 {
12
+ func hasCycle(_ head: ListNode?) -> Bool {
13
+ guard head != nil, head?.next != nil
14
+ else {
15
+ return false
16
+ }
17
18
+ var tortoise = head
19
+ var hare = head?.next
20
21
+ while hare != nil, hare?.next != nil {
22
+ if tortoise === hare { return true }
23
+ tortoise = tortoise?.next
24
+ hare = hare?.next?.next
25
26
27
28
29
+}
0 commit comments