zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1300. 转变数组后最接近目标值的数组和 | Sum of Mutated Array Closest to Target

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/12151631.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    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
    Output: 3
    Explanation: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer.
    Example 2:

    Input: arr = [2,3,5], target = 10
    Output: 5
    Example 3:

    Input: arr = [60864,25176,27249,21296,20204], target = 56803
    Output: 11361
     

    Constraints:

    1 <= arr.length <= 10^4
    1 <= arr[i], target <= 10^5


    给你一个整数数组 arr 和一个目标值 target ,请你返回一个整数 value ,使得将数组中所有大于 value 的值变成 value 后,数组的和最接近  target (最接近表示两者之差的绝对值最小)。

    如果有多种使得和最接近 target 的方案,请你返回这些整数中的最小值。

    请注意,答案不一定是 arr 中的数字。

    示例 1:

    输入:arr = [4,9,3], target = 10
    输出:3
    解释:当选择 value 为 3 时,数组会变成 [3, 3, 3],和为 9 ,这是最接近 target 的方案。
    示例 2:

    输入:arr = [2,3,5], target = 10
    输出:5
    示例 3:

    输入:arr = [60864,25176,27249,21296,20204], target = 56803
    输出:11361
     

    提示:

    1 <= arr.length <= 10^4
    1 <= arr[i], target <= 10^5

  • 相关阅读:
    sql server等待类型
    进程死锁运行状态、进程阻塞、死锁监控
    sql server安装教程(2008 R2,图形界面安装/命令提示符安装即静默安装/无人值守安装)
    (3.7)存储引擎--索引的结构与分类
    (3.6)存储引擎--文件与数据的结构
    (3.5)存储引擎--日志
    (3.4)存储引擎--内存
    (3.3)存储引擎--数据读写
    PhoneGap and Titanium
    touch
  • 原文地址:https://www.cnblogs.com/strengthen/p/12151631.html
Copyright © 2011-2022 走看看