Skip to content

Commit 263e016

Browse files
add a solution for 624
1 parent 52642b0 commit 263e016

File tree

1 file changed

+16
-0
lines changed
  • src/main/java/com/fishercoder/solutions/firstthousand

1 file changed

+16
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,20 @@ public int maxDistance(List<List<Integer>> arrays) {
2121
return ans;
2222
}
2323
}
24+
25+
public static class Solution2 {
26+
public int maxDistance(List<List<Integer>> arrays) {
27+
int min = arrays.get(0).get(0);
28+
int max = arrays.get(0).get(arrays.get(0).size() - 1);
29+
int ans = 0;
30+
for (int i = 1; i < arrays.size(); i++) {
31+
List<Integer> curr = arrays.get(i);
32+
ans = Math.max(ans, Math.abs(max - curr.get(0)));
33+
ans = Math.max(ans, Math.abs(curr.get(curr.size() - 1) - min));
34+
max = Math.max(max, curr.get(curr.size() - 1));
35+
min = Math.min(min, curr.get(0));
36+
}
37+
return ans;
38+
}
39+
}
2440
}

0 commit comments

Comments
 (0)