forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_624.java
24 lines (21 loc) · 776 Bytes
/
_624.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class _624 {
public static class Solution1 {
public int maxDistance(List<List<Integer>> arrays) {
List<Integer> max = new ArrayList<>();
for (List<Integer> array : arrays) {
max.add(array.get(array.size() - 1));
}
Collections.sort(max);
int ans = Integer.MIN_VALUE;
for (List<Integer> array : arrays) {
int big = array.get(array.size() - 1) == max.get(max.size() - 1) ? max.get(max.size() - 2) : max.get(max.size() - 1);
ans = Math.max(ans, big - array.get(0));
}
return ans;
}
}
}