主页 > 软件开发  > 

力扣每日一题【算法学习day.129】

力扣每日一题【算法学习day.129】
前言

###我做这类文章一个重要的目的还是记录自己的学习过程,我的解析也不会做的非常详细,只会提供思路和一些关键点,力扣上的大佬们的题解质量是非常非常高滴!!!


习题 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)); } }
后言

共勉

 

 

标签:

力扣每日一题【算法学习day.129】由讯客互联软件开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“力扣每日一题【算法学习day.129】