dw制作简单网站模板热门关键词排名查询
前言
###我做这类文章一个重要的目的还是记录自己的学习过程,我的解析也不会做的非常详细,只会提供思路和一些关键点,力扣上的大佬们的题解质量是非常非常高滴!!!
习题
1.数组列表中的最大距离
题目链接:624. 数组列表中的最大距离 - 力扣(LeetCode)
题面:
分析:麻烦点的做法就是先遍历一遍找到最大值,第二次遍历的时候跳过最大值那一行
代码:
class Solution {public int maxDistance(List<List<Integer>> arrays) {int max = Integer.MIN_VALUE;int min = Integer.MAX_VALUE;int index = 0;int flag = 0;for(List<Integer> list:arrays){for(int a:list){if(a>max){max = a;flag = index;}}index++;}index = 0;for(List<Integer> list:arrays){for(int a:list){if(a<min&&index!=flag){min = a;}}index++;}int max2 = Integer.MIN_VALUE;int min2 = Integer.MAX_VALUE;index = 0;flag = 0;for(List<Integer> list:arrays){for(int a:list){if(a<min2){min2 = a;flag = index;}}index++;}index = 0;for(List<Integer> list:arrays){for(int a:list){if(a>max2&&index!=flag){max2 = a;}}index++;}return Math.max(Math.abs(max-min),Math.abs(max2-min2));}
}
后言
共勉