File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change 3131 */
3232public 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}
You can’t perform that action at this time.
0 commit comments