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

  • 相关阅读:
    eCharts_数据过多底部滚动条实现数据展示
    canvas_简单练习
    canvas_基于canvan绘制的双半圆环进度条
    js_读【javascript面向对象编程指南】笔记
    csc_滤镜filter和实现透明的两种方式
    jq_从右向右的滑入滑出效果
    textarea输入框实时统计输入字符数
    windows7_常用操作终端操作
    1080. Graduate Admission (30)
    1079. Total Sales of Supply Chain (25)
  • 原文地址:https://www.cnblogs.com/strengthen/p/12151631.html
Copyright © 2011-2022 走看看