File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ public:
107107};
108108```
109109
110- 时间复杂度:$O(n)$
110+ 时间复杂度:$O(n)$
111111空间复杂度:$O(1)$
112112
113113** 一些录友会疑惑为什么时间复杂度是$O(n)$** 。
@@ -121,7 +121,6 @@ public:
121121
122122
123123
124-
125124## 其他语言版本
126125
127126
@@ -291,5 +290,23 @@ class Solution {
291290}
292291```
293292
293+ Ruby:
294+
295+ ``` ruby
296+ def min_sub_array_len (target , nums )
297+ res = Float ::INFINITY # 无穷大
298+ i, sum = 0 , 0
299+ nums.length.times do |j |
300+ sum += nums[j]
301+ while sum >= target
302+ res = [res, j - i + 1 ].min
303+ sum -= nums[i]
304+ i += 1
305+ end
306+ end
307+ res == Float ::INFINITY ? 0 : res
308+ end
309+ ```
310+
294311-----------------------
295312<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img ></div >
You can’t perform that action at this time.
0 commit comments