codility StoneWall

来源:互联网 发布:口袋妖怪编辑队伍软件 编辑:程序博客网 时间:2024/05/20 01:10

Question:codility Lesson7 StoneWall

My Answer:

def solution(H):    blockcnt = 0    stack = []    for height in H:        while len(stack) != 0 and stack[-1] > height:            stack.pop()            blockcnt += 1        if len(stack) == 0 or height > stack[-1]:            stack.append(height)            #blockcnt += 1    blockcnt += len(stack)    return blockcnt
原创粉丝点击