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

Commit2b3ef66

Browse files
add 2164
1 parent668223f commit2b3ef66

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-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+
|2164|[Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2164.java)||Easy||
1112
|2161|[Partition Array According to Given Pivot](https://leetcode.com/problems/partition-array-according-to-given-pivot/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2161.java)||Medium||
1213
|2160|[Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2160.java)||Easy||
1314
|2156|[Find Substring With Given Hash Value](https://leetcode.com/problems/find-substring-with-given-hash-value/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2156.java)||Medium||
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.Collections;
5+
importjava.util.List;
6+
7+
publicclass_2164 {
8+
publicstaticclassSolution1 {
9+
publicint[]sortEvenOdd(int[]nums) {
10+
List<Integer>odds =newArrayList<>();
11+
List<Integer>evens =newArrayList<>();
12+
for (inti =0;i <nums.length;i++) {
13+
if (i %2 ==0) {
14+
evens.add(nums[i]);
15+
}else {
16+
odds.add(nums[i]);
17+
}
18+
}
19+
Collections.sort(odds,Collections.reverseOrder());
20+
Collections.sort(evens);
21+
int[]ans =newint[nums.length];
22+
for (inti =0,j =0,k =0;i <nums.length;i++) {
23+
if (i %2 ==0) {
24+
ans[i] =evens.get(j++);
25+
}else {
26+
ans[i] =odds.get(k++);
27+
}
28+
}
29+
returnans;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp