-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2294.cpp
More file actions
38 lines (27 loc) · 808 Bytes
/
2294.cpp
File metadata and controls
38 lines (27 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<vector>
#include<algorithm>
int partitionArray(std::vector<int>& nums, int k) {
int num;
std::vector<int> temp = nums;
std::vector<std::vector<int>> subsequence(nums.size());
int size = temp.size() - 1;
std::sort(temp.begin(), temp.end());
subsequence[0].push_back(temp[size]);
// temp.erase(temp.begin() + size);
for(int i = 0; i < temp.size(); ++i) {
for(int j = 0; j < temp.size(); ++j) {
if(temp[size] - temp[size - 1] <= k) {
subsequence[i].push_back(temp[size]);
temp.erase(temp.begin() + size);
}
}
}
return num;
}
int main() {
std::vector<int> nums = { 3,6,1,2,5 };
int k = 2;
std::cout << partitionArray(nums, k);
std::cin.get();
}