There was an error while loading. Please reload this page.
2 parents 6482543 + d8bb038 commit 24c2020Copy full SHA for 24c2020
src/balanced_parentheses.rb
@@ -5,7 +5,9 @@ def balanced_parentheses?(str)
5
when '('
6
stack.push '('
7
when ')'
8
- if stack.empty? || stack.pop != '('
+ if !stack.empty?
9
+ stack.pop
10
+ else
11
return false
12
end
13
@@ -15,3 +17,4 @@ def balanced_parentheses?(str)
15
17
16
18
#test
19
p balanced_parentheses? '( () ( () ) () )' # => true
20
+p balanced_parentheses? '(()' # => false
0 commit comments