Skip to content

chore: use setAll func to initialize array in Java solution #4528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions solution/0500-0599/0506.Relative Ranks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ class Solution {
public String[] findRelativeRanks(int[] score) {
int n = score.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i1, i2) -> score[i2] - score[i1]);
String[] ans = new String[n];
String[] top3 = new String[] {"Gold Medal", "Silver Medal", "Bronze Medal"};
Expand Down
4 changes: 1 addition & 3 deletions solution/0500-0599/0506.Relative Ranks/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ class Solution {
public String[] findRelativeRanks(int[] score) {
int n = score.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i1, i2) -> score[i2] - score[i1]);
String[] ans = new String[n];
String[] top3 = new String[] {"Gold Medal", "Silver Medal", "Bronze Medal"};
Expand Down
4 changes: 1 addition & 3 deletions solution/0500-0599/0506.Relative Ranks/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Solution {
public String[] findRelativeRanks(int[] score) {
int n = score.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i1, i2) -> score[i2] - score[i1]);
String[] ans = new String[n];
String[] top3 = new String[] {"Gold Medal", "Silver Medal", "Bronze Medal"};
Expand Down
4 changes: 1 addition & 3 deletions solution/0800-0899/0853.Car Fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ class Solution {
public int carFleet(int target, int[] position, int[] speed) {
int n = position.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> position[j] - position[i]);
int ans = 0;
double pre = 0;
Expand Down
4 changes: 1 addition & 3 deletions solution/0800-0899/0853.Car Fleet/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ class Solution {
public int carFleet(int target, int[] position, int[] speed) {
int n = position.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> position[j] - position[i]);
int ans = 0;
double pre = 0;
Expand Down
4 changes: 1 addition & 3 deletions solution/0800-0899/0853.Car Fleet/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Solution {
public int carFleet(int target, int[] position, int[] speed) {
int n = position.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> position[j] - position[i]);
int ans = 0;
double pre = 0;
Expand Down
4 changes: 1 addition & 3 deletions solution/1300-1399/1340.Jump Game V/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ class Solution {
public int maxJumps(int[] arr, int d) {
int n = arr.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> arr[i] - arr[j]);
int[] f = new int[n];
Arrays.fill(f, 1);
Expand Down
4 changes: 1 addition & 3 deletions solution/1300-1399/1340.Jump Game V/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ class Solution {
public int maxJumps(int[] arr, int d) {
int n = arr.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> arr[i] - arr[j]);
int[] f = new int[n];
Arrays.fill(f, 1);
Expand Down
4 changes: 1 addition & 3 deletions solution/1300-1399/1340.Jump Game V/Solution2.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Solution {
public int maxJumps(int[] arr, int d) {
int n = arr.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> arr[i] - arr[j]);
int[] f = new int[n];
Arrays.fill(f, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ class Solution {
Arrays.sort(nums);
int n = queries.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> queries[i][1] - queries[j][1]);
int[] ans = new int[n];
Trie trie = new Trie();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ class Solution {
Arrays.sort(nums);
int n = queries.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> queries[i][1] - queries[j][1]);
int[] ans = new int[n];
Trie trie = new Trie();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public int[] maximizeXor(int[] nums, int[][] queries) {
Arrays.sort(nums);
int n = queries.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> queries[i][1] - queries[j][1]);
int[] ans = new int[n];
Trie trie = new Trie();
Expand Down
4 changes: 1 addition & 3 deletions solution/2400-2499/2418.Sort the People/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ class Solution {
public String[] sortPeople(String[] names, int[] heights) {
int n = names.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> heights[j] - heights[i]);
String[] ans = new String[n];
for (int i = 0; i < n; ++i) {
Expand Down
4 changes: 1 addition & 3 deletions solution/2400-2499/2418.Sort the People/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ class Solution {
public String[] sortPeople(String[] names, int[] heights) {
int n = names.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> heights[j] - heights[i]);
String[] ans = new String[n];
for (int i = 0; i < n; ++i) {
Expand Down
4 changes: 1 addition & 3 deletions solution/2400-2499/2418.Sort the People/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Solution {
public String[] sortPeople(String[] names, int[] heights) {
int n = names.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> heights[j] - heights[i]);
String[] ans = new String[n];
for (int i = 0; i < n; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ class Solution {
int n = nums.length;
boolean[] vis = new boolean[n + 2];
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> nums[i] - nums[j]);
long ans = 0;
for (int i : idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ class Solution {
int n = nums.length;
boolean[] vis = new boolean[n + 2];
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> nums[i] - nums[j]);
long ans = 0;
for (int i : idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ public long findScore(int[] nums) {
int n = nums.length;
boolean[] vis = new boolean[n + 2];
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> nums[i] - nums[j]);
long ans = 0;
for (int i : idx) {
Expand Down
4 changes: 1 addition & 3 deletions solution/2600-2699/2611.Mice and Cheese/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class Solution {
public int miceAndCheese(int[] reward1, int[] reward2, int k) {
int n = reward1.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> reward1[j] - reward2[j] - (reward1[i] - reward2[i]));
int ans = 0;
for (int i = 0; i < k; ++i) {
Expand Down
4 changes: 1 addition & 3 deletions solution/2600-2699/2611.Mice and Cheese/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ class Solution {
public int miceAndCheese(int[] reward1, int[] reward2, int k) {
int n = reward1.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> reward1[j] - reward2[j] - (reward1[i] - reward2[i]));
int ans = 0;
for (int i = 0; i < k; ++i) {
Expand Down
4 changes: 1 addition & 3 deletions solution/2600-2699/2611.Mice and Cheese/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Solution {
public int miceAndCheese(int[] reward1, int[] reward2, int k) {
int n = reward1.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> reward1[j] - reward2[j] - (reward1[i] - reward2[i]));
int ans = 0;
for (int i = 0; i < k; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ class Solution {
public int[] lexicographicallySmallestArray(int[] nums, int limit) {
int n = nums.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> nums[i] - nums[j]);
int[] ans = new int[n];
for (int i = 0; i < n;) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ class Solution {
public int[] lexicographicallySmallestArray(int[] nums, int limit) {
int n = nums.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> nums[i] - nums[j]);
int[] ans = new int[n];
for (int i = 0; i < n;) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Solution {
public int[] lexicographicallySmallestArray(int[] nums, int limit) {
int n = nums.length;
Integer[] idx = new Integer[n];
for (int i = 0; i < n; ++i) {
idx[i] = i;
}
Arrays.setAll(idx, i -> i);
Arrays.sort(idx, (i, j) -> nums[i] - nums[j]);
int[] ans = new int[n];
for (int i = 0; i < n;) {
Expand Down