[leetcode-908-Smallest Range I]
Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i].
After this process, we have some array B.
Return the smallest possible difference between the maximum value of B and the minimum value of B.
Example 1:
Input: A = [1], K = 0
Output: 0
Explanation: B = [1]
Example 2:
Input: A = [0,10], K = 2
Output: 6
Explanation: B = [2,8]
Example 3:
Input: A = [1,3,6], K = 3
Output: 0
Explanation: B = [3,3,3] or B = [4,4,4]
Note:
1 <= A.length <= 100000 <= A[i] <= 100000 <= K <= 10000
int smallestRangeI(vector<int>& A, int K)
{
int minV = A[], maxV = A[];
for(int i = ; i < A.size(); i++)
{
minV = min(minV, A[i]);
maxV = max(maxV, A[i]);
}
return max(((maxV - minV) - * K),);
}
[leetcode-908-Smallest Range I]的更多相关文章
- [LeetCode] 908. Smallest Range I 最小区间
Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and ...
- LeetCode 908 Smallest Range I 解题报告
题目要求 Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K ...
- 【Leetcode_easy】908. Smallest Range I
problem 908. Smallest Range I solution: class Solution { public: int smallestRangeI(vector<int> ...
- [LeetCode] 910. Smallest Range II 最小区间之二
Given an array A of integers, for each integer A[i] we need to choose either x = -K or x = K, and ad ...
- [LeetCode] 632. Smallest Range Covering Elements from K Lists 覆盖K个列表元素的最小区间
You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...
- [leetcode]632. Smallest Range最小范围
You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...
- 【LeetCode】908. Smallest Range I 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学计算 日期 题目地址:https://leetc ...
- [LeetCode&Python] Problem 908. Smallest Range I
Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and ...
- 【leetcode】908. Smallest Range I
题目如下: 解题思路:简单的不能再简单的题目了,对于任意一个A[i]来说,其可能的最小的最大值是A[i]-K,最大的最小值是A[i]+K.遍历数组,求出所有元素中最大的最小值和最小的最大值,两者之差( ...
- 解题报告-908. Smallest Range I
题目 : Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K ...
随机推荐
- oracle中的某一个用户名修改
1若修改某一个用户密码,修改用户口令格式为:alter user 用户名 identified by 新密码: 2以system 为例,想把密码修改为123456. 可输入alter user sys ...
- oracle 11G dataguard 恢复
检查主备机的sys 密码是否一致,忘记密码可以修改,同步 .alter user sys identified by xxx: orapwd file=oraxxx.ora password=admi ...
- @property & @synthesize & @dynamic 及相关属性作用探究
@property : iOS6 引入关键词. @property name; 指示编译器自动生成 name 的 setter 和 getter 方法 : - (NSString *)name; - ...
- Tomcat 或JBOSS java.lang.ArrayIndexOutOfBoundsException: 8192原因及其解决方法
2018-04-02 09:24:55 org.apache.catalina.connector.CoyoteAdapter service 严重: An exception or error oc ...
- svg图标(svg实现的QQ图标)
与传统的图片相比,用svg实现的图标要更好控制. 比如.若要改变图标的颜色,如果用图片的话,就需要UI设计人员调整图片,而如果用svg的话,就不用那么麻烦,开发人员改样式就行了. 附一个svg实现的Q ...
- MongoDB 简单上手
MongoDB 是什么 MongoDB 是一种非关系型数据库(NoSQL). MongoDB中的术语解释 文档(document):形如 { name: "sue", <-- ...
- usb驱动之打印usb设备信息(二)
以下是打印鼠标左右键及其他输入的源代码,详细说明见https://www.cnblogs.com/zhu-g5may/p/9309381.html /*参考/drivers/hid/usbhid/us ...
- PTA基础编程题目集6-7 统计某类完全平方数 (函数题)
本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144.676等. 函数接口定义: int IsTheNumber ( const int N ); 其中 ...
- FPGA千兆网UDP协议实现
接着上一篇百兆网接口的设计与使用,我们接着来进行FPGA百兆网UDP(User Datagram Protocol)协议的设计. 1)UDP简介 在此,参考博主夜雨翛然的博文“https://www. ...
- [2016北京集训测试赛5]小Q与内存-[线段树的神秘操作]
Description Solution 哇真的异常服气..线段树都可以搞合并和拆分的啊orzorz.神的世界我不懂 Code #include<iostream> #include< ...