Skip to content
Prev Previous commit
Next Next commit
20
  • Loading branch information
TedTran2019 committed Jul 8, 2022
commit 8cccb1def6002245552199116870ff49a791accc
17 changes: 17 additions & 0 deletions ruby/20-Valid-Parentheses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def is_valid(s)
paren = []
match = {
'{' => '}',
'(' => ')',
'[' => ']'
}
s.each_char do |char|
if match.key?(char)
paren << char
else
return false if paren.empty?
return false if match[paren.pop] != char
end
end
paren.empty?
end