[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 ...
随机推荐
- 执行 sql 报错未缓冲查询,错误码 2014
sql语句为 SELECT COUNT(id) AS tp_count FROM `tableName` WHERE `status` = 0 AND `source` = 1 AND ( `end_ ...
- Centos6.5中如何用sqlite3命令打开’.db’后缀的数据库执行sql
1. 简单sql语句使用: 在任意目录下新建一个数据库,比如student . 命令: sqlite3 student.db 出现如下提示: 输入sql语句create table user(us ...
- jQuey实现轮播图效果
再平常的浏览器页面,轮播图都是必不可缺少的一个板块,在这总结了一下轮播图基本的一些样式 首先介绍一下,本文实现的轮播图的基本效果: 1. 3s自动切换图片,图片切换时提示点跟随切换 2. 鼠标划到图片 ...
- iOS 11.4.1 正式版越狱
在 2018 年 Electra 最新能支持到 11.3.1 越狱,很长的一段时间 11.4 只能支持 Beta 版本,临近春节给了我们一个大礼物,终于支持 iOS 11.4-11.4.1,目前 iO ...
- 三、spring成长之路——springIOC容器详解(上)
目录 一.springIOC 一.springIOC 控制反转和依赖注入: 简单的说就是将对象的创建,属性的的设置交给spring容器进行管理,而不再由用户自己创建,当用户需要使用该接口或者类的时 ...
- HTML5纯Web前端也能开发直播,不用开发服务器(使用face2face)
前段时间转载了某位大神的一篇文章,开发Web版一对一远程直播教室只需30分钟 - 使用face2face网络教室.非常有意思.看起来非常简单,但作为一名前端开发人员来说,还是有难度.因为要开发服务器端 ...
- 05.kafka提前准备工作:搭建zookeeper集群环境
总体参考:http://www.cnblogs.com/zhangs1986/p/6564839.html 搭建之间同步下spark01.02.03的环境 复制/opt/flume这个文件夹到 spa ...
- EOS节点远程代码执行漏洞细节
这是一个缓冲区溢出越界写漏洞 漏洞存在于在 libraries/chain/webassembly/binaryen.cpp文件的78行, Function binaryen_runtime::ins ...
- ArrayList 一个面试题
我们现在有一个集合,集合里面有100个随机数,获取其中的基数: //假设我们得到了100个随机数 List<Integer> lists = new RandomArrayList< ...
- python 验证码识别初探
使用 pytesser 与 pytesseract 识别验证码 前置 : 首先需要安装 tesserract tesserract windows 安装包及中文 https://pan.baidu ...