update
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user