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 ...
随机推荐
- bhp 阅读笔记 OSX 下 setuptools pip 安装
安装 python-setuptools python-pip 尝试 brew install python-setuptools 失败 brew update 失败 $ cd `brew --pre ...
- Get Requests with Json Data && Get Requests with Url Parameters
- Ubuntu 16.04下的安装RabbitMQ
安装 添加源 echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/ra ...
- docker镜像基本操作一
获取镜像 首先说明一下如何从Docker hub中获取高质量的镜像,从Docker镜像库获取镜像的命令是docker pull .其命令格式为: docker pull [选项] [Docker Re ...
- Python中线程与互斥锁
了解之前我们先了解一下什么是多任务? 概念: 几个不同的事件在同时运行就是多任务, 这样的话, 我们有牵扯到了真的多任务, 假的多任务; 并行: 真的多任务, 通过电脑的核数来确定 并发: 假的多任务 ...
- WSGI学习系列WebOb
1. WSGI Server <-----> WSGI Middleware<-----> WSGI Application 1.1 WSGI Server wsgi ser ...
- mongodb-地理坐标存储查询
mongodb可支持空间地理搜索: 查询器 $geoWithin Selects geometries within a bounding GeoJSON geometry. The 2dsphere ...
- mysql 导出数据到csv文件的命令
1.导出本地数据库数据到本地文件 mysql -A service_db -h your_host -utest -ptest mysql> select * from t_apps where ...
- boost::asio基本使用
一.Asio网络库 截止到C++17,C++标准库都没有加入网络通信库.实际项目网络编程是非常常见的功能,直接使用操作系统API是低效率且不稳定的,比较好的方法是借助第三方成熟可靠的网络库.据我所知C ...
- 【BI】资料收集
从无到有--什么是BI 什么是BI(Business Intelligence) - @我爱菊花 - 博客园 http://www.cnblogs.com/jiesin/archive/2008/06 ...