Skip to content

Commit 0b50a15

Browse files
committed
Time: 137 ms (5.03%), Space: 153.2 MB (6.52%) - LeetHub
1 parent eb565dd commit 0b50a15

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
vector<int> pivotArray(vector<int>& nums, int pivot) {
4+
vector<array<int, 2>> temp;
5+
int n = nums.size();
6+
for (int i = 0; i < n; i++) {
7+
temp.push_back({nums[i], i});
8+
}
9+
sort(temp.begin(), temp.end());
10+
11+
int x = 0;
12+
while (x < n && temp[x][0] != pivot) x++;
13+
14+
auto cmp = [&](auto& a, auto& b) {
15+
return a[1] < b[1];
16+
};
17+
18+
sort(temp.begin(), temp.begin() + x, cmp);
19+
while (x < n && temp[x][0] == pivot) x++;
20+
sort(temp.begin() + x, temp.end(), cmp);
21+
vector<int> ans;
22+
for (auto& i : temp) ans.push_back(i[0]);
23+
return ans;
24+
}
25+
};

0 commit comments

Comments
 (0)