Skip to content

Commit 56e1262

Browse files
authored
Create stone_wall.rb
1 parent 8039188 commit 56e1262

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

stone_wall.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(h)
2+
blocks = 0
3+
stack = []
4+
h.each do |el|
5+
while !stack.empty? && stack.last > el do
6+
stack.pop()
7+
end
8+
9+
if !stack.empty? && stack.last == el
10+
else
11+
stack.push(el)
12+
blocks += 1
13+
end
14+
15+
end
16+
blocks
17+
end

0 commit comments

Comments
 (0)