mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-06 23:41:36 +00:00
为链表篇 增加 Swift 实现
This commit is contained in:
@@ -108,3 +108,20 @@ class Solution:
|
||||
return False
|
||||
```
|
||||
|
||||
Swift Code:
|
||||
|
||||
```swift
|
||||
class Solution {
|
||||
func hasCycle(_ head: ListNode?) -> Bool {
|
||||
var fast = head, slow = head
|
||||
while fast != nil && fast?.next != nil {
|
||||
fast = fast?.next?.next
|
||||
slow = slow?.next
|
||||
if fast === slow {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user