Skip to content

Commit 6a9e043

Browse files
refactor 624
1 parent 4c1626c commit 6a9e043

File tree

1 file changed

+13
-12
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-12
lines changed

src/main/java/com/fishercoder/solutions/_624.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@
3131
*/
3232
public class _624 {
3333

34-
public int maxDistance(int[][] arrays) {
35-
List<Integer> max = new ArrayList<>();
36-
for (int[] array : arrays) {
37-
max.add(array[array.length - 1]);
34+
public static class Solution1 {
35+
public int maxDistance(int[][] arrays) {
36+
List<Integer> max = new ArrayList<>();
37+
for (int[] array : arrays) {
38+
max.add(array[array.length - 1]);
39+
}
40+
Collections.sort(max);
41+
int ans = Integer.MIN_VALUE;
42+
for (int[] array : arrays) {
43+
int big = array[array.length - 1] == max.get(max.size() - 1) ? max.get(max.size() - 2) : max.get(max.size() - 1);
44+
ans = Math.max(ans, big - array[0]);
45+
}
46+
return ans;
3847
}
39-
Collections.sort(max);
40-
int ans = Integer.MIN_VALUE;
41-
for (int[] array : arrays) {
42-
int big = array[array.length - 1] == max.get(max.size() - 1) ? max.get(max.size() - 2) : max.get(max.size() - 1);
43-
ans = Math.max(ans, big - array[0]);
44-
}
45-
return ans;
4648
}
47-
4849
}

0 commit comments

Comments
 (0)