Code Signal_练习题_Make Array Consecutive2
Description
Ratiorg got statues
of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1
. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.
Example
For statues = [6, 2, 3, 8]
, the output should bemakeArrayConsecutive2(statues) = 3
.
Ratiorg needs statues of sizes 4
, 5
and 7
.
我的解答:
def makeArrayConsecutive2(statues):
count = 0
for i in range(min(statues),max(statues)):
if i not in statues:
print(i)
count += 1
return '总共需要以上%s个雕像'%count
膜拜大神:
def makeArrayConsecutive2(statues):
return max(statues) - min(statues) - len(statues) + 1
Code Signal_练习题_Make Array Consecutive2的更多相关文章
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
- Code Signal_练习题_Array Replace
Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem. Exam ...
- Code Signal_练习题_adjacentElementsProduct
Given an array of integers, find the pair of adjacent elements that has the largest product and retu ...
- Code Signal_练习题_almostIncreasingSequence
Given a sequence of integers as an array, determine whether it is possible to obtain a strictly incr ...
- Code Signal_练习题_All Longest Strings
Given an array of strings, return another array containing all of its longest strings. Example For i ...
- Code Signal_练习题_arrayChange
You are given an array of integers. On each move you are allowed to increase exactly one of its elem ...
随机推荐
- Volley源码解析
说点题外话,将近三个半月没有写博客了,年初换工作,在新的公司,上班第三天开始干活,花了二十来天弄了一个项目,上线后,接着又迭代了几个版本,不知不觉,试用期过完,才稍微有几天闲时.在年初的时候,就一直在 ...
- android应用程序的混淆打包
android应用程序的混淆打包 1 . 在工程文件project.properties中加入下proguard.config=proguard.cfg , 如下所示: target=android- ...
- 有关Hadoop的六大误解
迄今为止,Hadoop和大数据实际上是同义词.然而随着大数据的炒作不断升温,出现了很多对Hadoop如何应用于大数据的误解. Hadoop是一种用于存储和分析大型数据集开源软件框架,可处理分布在多个现 ...
- Java之IO(十二)CharArrayReader和CharArrayWriter
转载请注明源出处:http://www.cnblogs.com/lighten/p/7082668.html 1.前言 本章介绍字符数组流,作用和ByteArrayInputStream字节数组流相同 ...
- css设置:图片文字等不能被选择
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
- PHP中 LFI Local File Include,本地文件包 漏洞
在allow_url_include=On就是远程文件包含了,假设这里为off,那就只能本地包含了. 1. 包含上传文件 只要目标服务器支持上传,不管是jpg,txt,gif等都可以,在其 ...
- ztree树的递归
function clickAssignBtn(){ $('#assignBtn').off('click').on('click',function(){ var checkFlag=getRole ...
- ambari 2.6.2 安装 hdp 2.6.5.0 遇到的问题
1.hive-client 无法安装 一直报错(symlink target already exists and it is not a symlink.),hive-client 已经存在且不是 ...
- java学习--Reflection反射机制
JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意方法和属性:这种动态获取信息以及动态调用对象方法的功能称为java语言的反射机制. ...
- springboot-15-启动时加载数据的方法CommandLineRunner
有时需要爱项目启动时, 去加载一些配置文件什么的, 可以使用监听器的方式加载, 这是可以通过实现接口 CommandLineRunner来实现需求: Spring Boot应用程序在启动后,会遍历Co ...