Skip to content

Commit 017573f

Browse files
authored
Update partition-array-according-to-given-pivot.cpp
1 parent a3686e7 commit 017573f

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

C++/partition-array-according-to-given-pivot.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
class Solution {
66
public:
77
vector<int> pivotArray(vector<int>& nums, int pivot) {
8-
int less = 0, greater = 0;
9-
for (const auto& x : nums) {
10-
if (x < pivot) {
11-
++less;
12-
} else if (x > pivot) {
13-
++greater;
14-
}
15-
}
168
vector<int> result(size(nums), pivot);
17-
int left = 0, right = size(nums) - greater;
9+
int left = 0, right = size(nums) - count_if(cbegin(nums), cend(nums), [&pivot](const auto& x) { return x > pivot; });
1810
for (const auto& x: nums) {
1911
if (x < pivot) {
2012
result[left++] = x;

0 commit comments

Comments
 (0)