-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxDistanceInArrays.java
More file actions
59 lines (43 loc) · 1.19 KB
/
Copy pathmaxDistanceInArrays.java
File metadata and controls
59 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package LeetCode;
import java.util.ArrayList;
import java.util.List;
import javax.swing.text.html.HTMLDocument.Iterator;
public class maxDistanceInArrays {
public static int maxDistance(List<List<Integer>> arrays) {
int len = arrays.size();
int min = arrays.get(0).get(0), max = arrays.get(0).get(0);
int arrNum = 0;
for (int i = 0; i < len; i++) {
List<Integer> temp = arrays.get(i);
int tmpLen = temp.size();
for (int j = 0; j < tmpLen; j++) {
if (temp.get(j) > max && arrNum != i){
max = temp.get(j);
arrNum = !
}
if (temp.get(j) < min)
min = temp.get(j);
}
}
return max - min;
}
public static void main(String[] args) {
List<List<Integer>> list = new ArrayList<List<Integer>>();
List<Integer> list1 = new ArrayList<Integer>();
List<Integer> list2 = new ArrayList<Integer>();
List<Integer> list3 = new ArrayList<Integer>();
list1.add(1);
list1.add(2);
list1.add(3);
list2.add(4);
list2.add(5);
list3.add(1);
list3.add(2);
list3.add(3);
list.add(list1);
list.add(list2);
list.add(list3);
int res = maxDistance(list);
System.out.println(res);
}
}