在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target. In case of a tie, return the minimum such integer. Notice that the answer is not neccesarilly a number from arr.
Example 1: Input: arr = [4,9,3], target = 10 Input: arr = [2,3,5], target = 10 Input: arr = [60864,25176,27249,21296,20204], target = 56803 Constraints: 1 <= arr.length <= 10^4 给你一个整数数组 arr 和一个目标值 target ,请你返回一个整数 value ,使得将数组中所有大于 value 的值变成 value 后,数组的和最接近 target (最接近表示两者之差的绝对值最小)。 如果有多种使得和最接近 target 的方案,请你返回这些整数中的最小值。 请注意,答案不一定是 arr 中的数字。
示例 1: 输入:arr = [4,9,3], target = 10 输入:arr = [2,3,5], target = 10 输入:arr = [60864,25176,27249,21296,20204], target = 56803 提示: 1 <= arr.length <= 10^4 |
请发表评论