We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3e563ce commit 39a1c39Copy full SHA for 39a1c39
2529/solution.cpp
@@ -0,0 +1,14 @@
1
+// binary search the lower/upper bound indices of zeroes
2
+
3
+class Solution {
4
+public:
5
+ int maximumCount(vector<int>& A) {
6
+ auto it = A.begin();
7
+ int l = lower_bound(A.begin(), A.end(), 0) - it; // the lower index of zeroes
8
+ int r = upper_bound(A.begin(), A.end(), 0) - it; // the upper index of zeroes
9
+ return std::max(
10
+ l,
11
+ (int)A.size() - r
12
+ );
13
+ }
14
+};
0 commit comments