Skip to content

Commit 39a1c39

Browse files
committed
Add C++ solution of problem #2529
1 parent 3e563ce commit 39a1c39

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

2529/solution.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)