LeetCode #1131 Maximum of Absolute Value Expression 绝对值表达式的最大

分享
源代码 2024-9-23 22:01:29 99 0 来自 中国
1131 Maximum of Absolute Value Expression 绝对值表达式的最大值

Description:
Given two arrays of integers with equal lengths, return the maximum value of:
|arr1 - arr1[j]| + |arr2 - arr2[j]| + |i - j|
where the maximum is taken over all 0 <= i, j < arr1.length.
Example:
Example 1:
Input: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
Output: 13
Example 2:
Input: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
Output: 20
Constraints:
2 <= arr1.length == arr2.length <= 40000
-10^6 <= arr1, arr2 <= 10^6
标题描述:
给你两个长度相称的整数数组,返回下面表达式的最大值:
|arr1 - arr1[j]| + |arr2 - arr2[j]| + |i - j|
其中下标 i,j 满意 0 <= i, j < arr1.length。
示例 :
示例 1:
输入:arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
输出:13
示例 2:
输入:arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
输出:20
提示:
2 <= arr1.length == arr2.length <= 40000
-10^6 <= arr1, arr2 <= 10^6
思绪:
数学
将绝对值符号去掉一共有 8 种组合
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-11-22 18:16, Processed in 0.117571 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表