mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-10 09:01:58 +00:00
为数组篇 增加 Swift 实现
This commit is contained in:
@@ -106,3 +106,22 @@ class Solution:
|
||||
return windowlen
|
||||
```
|
||||
|
||||
Swift Code
|
||||
|
||||
```swift
|
||||
class Solution {
|
||||
func minSubArrayLen(_ target: Int, _ nums: [Int]) -> Int {
|
||||
|
||||
var sum = 0, windowlen = Int.max, i = 0
|
||||
for j in 0..<nums.count {
|
||||
sum += nums[j]
|
||||
while sum >= target {
|
||||
windowlen = min(windowlen, j - i + 1)
|
||||
sum -= nums[i]
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
return windowlen == Int.max ? 0 : windowlen
|
||||
}
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user