Merge pull request #86 from xiao2shiqi/phoenix-work-branch
添加 0020.有效的括号 ruby 版本
This commit is contained in:
commit
e390d9030a
|
|
@ -202,6 +202,23 @@ func isValid(s string) bool {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue