This commit is contained in:
2026-05-03 23:48:22 +08:00
parent ffdbb39158
commit eaed0664f3
2 changed files with 243 additions and 0 deletions
+24
View File
@@ -57,3 +57,27 @@ what is using?
we need to write binary search, lower bound search
learn about binary search functions the natural one by god
keep
#+begin_src c++
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
bool state = false;
int prev = 0;
int best = 0;
nums.push_back(0);
for (int i=0; i<nums.size(); i++) {
if (!state && nums[i]==1) {
prev = i;
state = true;
} else if (state && nums[i]==0) {
best = std::max(best, i-prev);
state = false;
}
}
return best;
}
};
#+end_src