Calculate the values of counters after applying all alternating operations:
increase counter by 1; set value of all counters to current maximum.
方法一:按照規則用 loop 慢慢解
```python
def solution(N, A):
result = [0] * N
minValue = 0
maxValue = 0
for number in A:
index = number - 1
if(index == N):
minValue = maxValue
continue
result[index] = max(result[index], minValue) + 1
maxValue = max(maxValue, result[index])
for i in range(N):
result[i] = max(result[i], minValue)
return result
```
完整練習題 source code 請參閱:github
沒有留言:
張貼留言