Skip to content

Commit

Permalink
20
Browse files Browse the repository at this point in the history
  • Loading branch information
TedTran2019 committed Jul 8, 2022
1 parent be78ba0 commit 8cccb1d
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 8cccb1d

Please sign in to comment.