Skip to content

Commit 685446f

Browse files
authored
Create bulb-switcher-iii.cpp
1 parent 0870eda commit 685446f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

C++/bulb-switcher-iii.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int numTimesAllBlue(vector<int>& light) {
7+
int result = 0, right = 0;
8+
for (int i = 0; i < light.size(); ++i) {
9+
right = max(right, light[i]);
10+
result += (i + 1 == right);
11+
}
12+
return result;
13+
}
14+
};

0 commit comments

Comments
 (0)