lz的代码:
height = [5, 3, 1, 2, 4, 6, 2, 4]
ans = 0
n = len(height)
h = max(height)
for i in range(1, h+1):
head = 0
tail = 0
while tail < n-1:
if height[head] >= i and height[head+1] < i :
tail = tail+1
while height[tail] < i and tail < n:
tail = tail+1
if tail >= n:
break
else:
ans+= tail-head-1
head=tail
continue
tail+= 1
head+= 1
print(ans)
height = [5, 3, 1, 2, 4, 6, 2, 4]
ans = 0
n = len(height)
h = max(height)
for i in range(1, h+1):
head = 0
tail = 0
while tail < n-1:
if height[head] >= i and height[head+1] < i :
tail = tail+1
while height[tail] < i and tail < n:
tail = tail+1
if tail >= n:
break
else:
ans+= tail-head-1
head=tail
continue
tail+= 1
head+= 1
print(ans)