常州手机网站效果,wordpress 登陆图标,各大网站开发的区块链,安阳网站制作 网络服务前言
###我做这类文章一个重要的目的还是记录自己的学习过程#xff0c;我的解析也不会做的非常详细#xff0c;只会提供思路和一些关键点#xff0c;力扣上的大佬们的题解质量是非常非常高滴#xff01;#xff01;#xff01; 习题
1.数组列表中的最大距离
题目链接…前言
###我做这类文章一个重要的目的还是记录自己的学习过程我的解析也不会做的非常详细只会提供思路和一些关键点力扣上的大佬们的题解质量是非常非常高滴 习题
1.数组列表中的最大距离
题目链接:624. 数组列表中的最大距离 - 力扣LeetCode
题面:
分析:麻烦点的做法就是先遍历一遍找到最大值第二次遍历的时候跳过最大值那一行
代码:
class Solution {public int maxDistance(ListListInteger arrays) {int max Integer.MIN_VALUE;int min Integer.MAX_VALUE;int index 0;int flag 0;for(ListInteger list:arrays){for(int a:list){if(amax){max a;flag index;}}index;}index 0;for(ListInteger list:arrays){for(int a:list){if(aminindex!flag){min a;}}index;}int max2 Integer.MIN_VALUE;int min2 Integer.MAX_VALUE;index 0;flag 0;for(ListInteger list:arrays){for(int a:list){if(amin2){min2 a;flag index;}}index;}index 0;for(ListInteger list:arrays){for(int a:list){if(amax2index!flag){max2 a;}}index;}return Math.max(Math.abs(max-min),Math.abs(max2-min2));}
} 后言
共勉