Skip to content

Commit 8039188

Browse files
authored
Create nesting.rb
1 parent 125db8e commit 8039188

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

nesting.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def solution(s)
2+
return 1 if s.length == 0
3+
open_stack = []
4+
s.split("").each do |el|
5+
if el == "("
6+
open_stack.push(el)
7+
else
8+
return 0 if open_stack.length == 0
9+
open_stack.pop
10+
end
11+
end
12+
open_stack.length == 0 ? 1 : 0
13+
end

0 commit comments

Comments
 (0)