mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
2022-0102: 0209 add ruby version
This commit is contained in:
@ -121,7 +121,6 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
|
||||||
@ -291,5 +290,23 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Ruby:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
def min_sub_array_len(target, nums)
|
||||||
|
res = Float::INFINITY # 无穷大
|
||||||
|
i, sum = 0, 0
|
||||||
|
nums.length.times do |j|
|
||||||
|
sum += nums[j]
|
||||||
|
while sum >= target
|
||||||
|
res = [res, j - i + 1].min
|
||||||
|
sum -= nums[i]
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
res == Float::INFINITY ? 0 : res
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||||
|
Reference in New Issue
Block a user