Skip to content

Commit 8cccb1d

Browse files
committed
20
1 parent be78ba0 commit 8cccb1d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ruby/20-Valid-Parentheses.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def is_valid(s)
2+
paren = []
3+
match = {
4+
'{' => '}',
5+
'(' => ')',
6+
'[' => ']'
7+
}
8+
s.each_char do |char|
9+
if match.key?(char)
10+
paren << char
11+
else
12+
return false if paren.empty?
13+
return false if match[paren.pop] != char
14+
end
15+
end
16+
paren.empty?
17+
end

0 commit comments

Comments
 (0)