1 class Solution:
2     def numTimesAllBlue(self, light: 'List[int]') -> int:
3         right,res = 0,0
4         for i, a in enumerate(light, start=1):
5             right = max(right, a)
6             if right == i:
7                 res += 1
8         return res

算法思路:数组。

参考:https://leetcode.com/problems/bulb-switcher-iii/discuss/532538/JavaC%2B%2BPython-Straight-Forward-O(1)-Space

posted on 2020-03-08 13:10  Sempron2800+  阅读(142)  评论(0编辑  收藏  举报