为链表篇 增加 Swift 实现

This commit is contained in:
frank-tian
2021-07-17 22:28:06 +08:00
parent a16c030b44
commit 7b55df11dc
14 changed files with 499 additions and 3 deletions

View File

@@ -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
}
}
```