Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e0f0d6

Browse files
add 2099
1 parenta315ee1 commit9e0f0d6

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_2099 {
6+
publicstaticclassSolution1 {
7+
publicint[]maxSubsequence(int[]nums,intk) {
8+
int[][]map =newint[nums.length][2];
9+
for (inti =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 =newint[k][2];
15+
for (inti =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 =newint[k];
21+
for (inti =0;i <k;i++) {
22+
ans[i] =arr[i][0];
23+
}
24+
returnans;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp