[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 ...
随机推荐
- Spring boot 零配置开发微服务
2018年12月29日星期六 体验Spring boot 零配置开发微服务 1.为什么要用Spring boot? 1.1 简单方便.配置少.整合了大多数框架 1.2 适用于微服务搭建,搭建的微服务 ...
- python爬虫练习 -- 签名器+GUI界面(Tkinter)
效果图: 实现步骤如下: 实现原理:其实就是套了一层GUI的壳,主要还是爬虫抓取某个网站返回的数据,然后利用python自带的GUI工具包Tkinter来实现gui界面: 1.爬虫分析: 目标站点:h ...
- Django学习笔记6(iframe、外键插入)
1.{%include 'index.html'%i} 平时很好用的iframe在django里面的不是很好用 django里面提供了{%include 'index.html'%i}的方式来取代了i ...
- 如何安装使用MinDoc搭建个人在线wiki文档
MinDoc是什么? MinDoc是一个在线的文档管理系统,该系统适用于团队.个人等使用.开发者最初的目的是为了便于公司内部使用,仿照看云开发.有laravel版本以及golang版本.不过larav ...
- 20155203 实验一《Java开发环境的熟悉》实验报告
20155203 实验一<Java开发环境的熟悉>实验报告 一.实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 二.练 ...
- 学号20155311 2016-2017-2 《Java程序设计》第一次实验报告
课程:Java程序设计 实验名称:Java开发环境的熟悉 实验目的与要求: 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器> 课程: 完成实验. ...
- 20155313 2016-2017-2 《Java程序设计》第九周学习总结
20155313 2016-2017-2 <Java程序设计>第九周学习总结 教材学习内容总结 第16章 JDBC(Java DataBase Connectivity)即java数据库连 ...
- day 6 汽车4S店铺
1.版本1:大框架 class CarStore(object): '''定义一个汽车店铺类''' pass class Car(object): '''定义一个汽车类''' pass car_sto ...
- 【bzoj4827】[Hnoi2017]礼物 FFT
题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在她生日的前一天 ...
- The specified value "2019-1-2" does not conform to the required format, "yyyy-MM-dd"
问题: 在cshtml中转换的日期格式错误,前端报错:The specified value "2019-1-2" does not conform to the required ...