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. 1 <= A.length <= 10000
  2. 0 <= A[i] <= 10000
  3. 0 <= 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),);
}

最新文章

  1. .NET面试题系列[9] - IEnumerable
  2. 【开源】OSharp框架解说系列(5.2):EntityFramework数据层实现
  3. Android Studio--学习系列(2)
  4. C++设计模式-Strategy策略模式
  5. Python3基础 使用技巧:把代码的字体变大
  6. WP8__从windowsphone app store 中根据app id获取应用的相关信息(下载网址及图片id等)
  7. Graylog2+mongdb+rsyslog中央日志服务器对syslog的web管理--转载
  8. Chrome浏览器跨域问题
  9. 为UITextView添加与UITextField一样的边框——UITextField默认边框颜色、宽度、圆角
  10. 【Xamarin挖墙脚系列:现有IPhone/IPad 设备尺寸】
  11. HDU 5651 xiaoxin juju needs help 水题一发
  12. YII中文件上传
  13. Dev表格导出工具类 z
  14. 判断mysqli函数里的sql语句是否有错和影响行数
  15. 楼天城楼教主的acm心路历程(作为励志用)
  16. redhat6.3+oracle11GR2 单库 安装规划
  17. Nagios监控生产环境redis群集服务战
  18. MySQL意外关闭, 导致软件崩溃而无法启动的解决办法
  19. 在非controllers中获取httpServletRequest
  20. 【转】C++ Vector(向量容器)

热门文章

  1. Eclipse部署Web项目,常用操作和常见错误的解决方案
  2. debug?用对拍!
  3. Ubuntu SSH登陆出现Access Denied错误
  4. Innodb和Mysiam引擎的区别
  5. Android开发 使用HBuilder的缓存方法
  6. [示例] Firemonkey TreeView 父项勾选子项连动
  7. etl是什么
  8. NIH周三讲座视频爬虫
  9. 记账APP(5)
  10. mybash的编写与调试