leetcode624: Maximum Distance in Arrays
来源:互联网 发布:怎么查看网络是否稳定 编辑:程序博客网 时间:2024/06/06 02:56
Given m
arrays, and each array is sorted in ascending order. Now you can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a
and b
to be their absolute difference |a-b|
. Your task is to find the maximum distance.
Example 1:
Input: [[1,2,3], [4,5], [1,2,3]]Output: 4Explanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.
Note:
- Each given array will have at least 1 number. There will be at least two non-empty arrays.
- The total number of the integers in all the
m
arrays will be in the range of [2, 10000]. - The integers in the
m
arrays will be in the range of [-10000, 10000].
public int maxDistance(int[][] arrays) {int res = 0;int min = arrays[0][0];int max = arrays[0][arrays[0].length - 1];for (int i = 1; i < arrays.length; i++) {res = Math.max(res, Math.abs(arrays[i][arrays[i].length - 1] - min));res = Math.max(res, Math.abs(arrays[i][0] - max));max = Math.max(max, arrays[i][arrays[i].length - 1]);min = Math.min(min, arrays[i][0]);}return res;}
阅读全文
0 0
- leetcode624: Maximum Distance in Arrays
- leetcode624. Maximum Distance in Arrays
- leetcode-624. Maximum Distance in Arrays
- [leetcode]: 624. Maximum Distance in Arrays
- [LeetCode]624. Maximum Distance in Arrays
- [LeetCode]624. Maximum Distance in Arrays
- [LeetCode] 624.Maximum Distance in Arrays
- Leetcode 624 Maximum Distance in Arrays
- Python 刷题日记:LeetCode 624. Maximum Distance in Arrays
- Maximum Distance in Arrays (第十七周 数组)
- 624.Maximum Distance in Arrays --找数组中的最大差值
- 624. Maximum Distance in Arrays 数组最大距离
- 566. Reshape the Matrix/624. Maximum Distance in Arrays/594. Longest Harmonious Subsequence
- LeetCode-624:Maximum Distance in Arrays (多数组找元素最大距离)
- hdu3585 maximum shortest distance
- Maximum array distance Sum
- [LeetCode] Maximum Subarray、Edit Distance
- Distance in Matlab
- leetcode-625. Minimum Factorization
- AMD、CMD、webpack理解
- Android中View绘制过程(四) performMeasure
- http切换到https的tomcat配置
- Oracle中的闪回
- leetcode624: Maximum Distance in Arrays
- 3-python 函数篇
- javascript中的数值转换与逻辑非的比较
- jsp页面的前进刷新后退
- 用好React,你必须要知道的事情
- HBase性能优化方法总结(三):读表操作
- High Quality with High Performance UE4 Mobile Game
- 《PRML》第一章 读书笔记.1
- JSP:JSP指令元素:page指令,include指令,taglib指令