Skip to content

Commit f68760d

Browse files
authored
Create 2099. Find Subsequence of Length K With the Largest Sum (#827)
2 parents 99e10e0 + ec7cb87 commit f68760d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
vector<int> maxSubsequence(vector<int>& nums, int k) {
4+
vector<pair<int, int>>ans;
5+
vector<int>arr;
6+
for(int i=0; i<nums.size(); i++){
7+
ans.push_back({i, nums[i]});
8+
}
9+
auto lambda=[](auto p1, auto p2){
10+
return p1.second>p2.second;
11+
};
12+
sort(ans.begin(), ans.end(), lambda);
13+
sort(ans.begin(), ans.begin()+k);
14+
for(int i=0; i<k; i++){
15+
arr.push_back(ans[i].second);
16+
}
17+
return arr;
18+
}
19+
};

0 commit comments

Comments
 (0)