Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9e0f0d6

Browse files
add 2099
1 parent a315ee1 commit 9e0f0d6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2099|[Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2099.java) ||Easy||
1112
|2095|[Delete the Middle Node of a Linked List](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2095.java) ||Medium||
1213
|2094|[Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2094.java) ||Easy||
1314
|2091|[Removing Minimum and Maximum From Array](https://leetcode.com/problems/removing-minimum-and-maximum-from-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2091.java) ||Medium||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _2099 {
6+
public static class Solution1 {
7+
public int[] maxSubsequence(int[] nums, int k) {
8+
int[][] map = new int[nums.length][2];
9+
for (int i = 0; i < nums.length; i++) {
10+
map[i][0] = nums[i];
11+
map[i][1] = i;
12+
}
13+
Arrays.sort(map, (a, b) -> b[0] - a[0]);
14+
int[][] arr = new int[k][2];
15+
for (int i = 0; i < k; i++) {
16+
arr[i][0] = map[i][0];
17+
arr[i][1] = map[i][1];
18+
}
19+
Arrays.sort(arr, (a, b) -> a[1] - b[1]);
20+
int[] ans = new int[k];
21+
for (int i = 0; i < k; i++) {
22+
ans[i] = arr[i][0];
23+
}
24+
return ans;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)