Skip to content

Commit 24c2020

Browse files
authored
Merge pull request #40 from christianbender/changed_balanced_parenthesis
simplified the function balanced_parentheses?
2 parents 6482543 + d8bb038 commit 24c2020

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/balanced_parentheses.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ def balanced_parentheses?(str)
55
when '('
66
stack.push '('
77
when ')'
8-
if stack.empty? || stack.pop != '('
8+
if !stack.empty?
9+
stack.pop
10+
else
911
return false
1012
end
1113
end
@@ -15,3 +17,4 @@ def balanced_parentheses?(str)
1517

1618
#test
1719
p balanced_parentheses? '( () ( () ) () )' # => true
20+
p balanced_parentheses? '(()' # => false

0 commit comments

Comments
 (0)