添加 0020.有效的括号 Ruby 版本
This commit is contained in:
parent
f5d2d2ca66
commit
c4de753d6d
|
|
@ -336,6 +336,23 @@ var threeSum = function(nums) {
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
ruby:
|
||||||
|
```ruby
|
||||||
|
def is_valid(strs)
|
||||||
|
symbol_map = {')' => '(', '}' => '{', ']' => '['}
|
||||||
|
stack = []
|
||||||
|
strs.size.times {|i|
|
||||||
|
c = strs[i]
|
||||||
|
if symbol_map.has_key?(c)
|
||||||
|
top_e = stack.shift
|
||||||
|
return false if symbol_map[c] != top_e
|
||||||
|
else
|
||||||
|
stack.unshift(c)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
stack.empty?
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue