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 ...
随机推荐
- webpack初学者(1)
最近在学习webpack的总结,不完善的希望各位提出宝贵的建议.本篇是以webpack3.0版本为基础的学习总结. 一.webpack的概念及作用 wepack是一个模块打包兼优化工具.往往一个项目中 ...
- error "Can only specify query options (orderby, where, take, skip) after last navigation" when fetching a List<string>
Question I use OData v3 and WCF in visual studio 2012. I want to return List<string> using the ...
- 剑指offer五十六之删除链表中重复的结点
一.题目 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4->5 处理后 ...
- tensorflow基础篇-2
#-*- coding:utf-8 -*- import tensorflow as tf sess=tf.Session() #整流水线单元relu print sess.run(tf.nn.rel ...
- 数据库-SQLite简介
SQLite是D.Richard Hipp用C语言编写的开源嵌入式数据库(轻型数据库). 由于资源占用少.性能良好和零管理成本,嵌入式数据库有了它的用武之地,像Android.iPhone都有内置的S ...
- google glog 使用方法
#include <glog/logging.h> int main(int argc,char* argv[]) { google::ParseCommandLineFlags(& ...
- MySQL查询时区分大小写
在创建MySQL数据库时,下面这些参数可供我们选择:*_bin: 表示的是binary case sensitive collation,也就是说是区分大小写的 *_cs: case sensitiv ...
- Python远程连接主机之paramiko模块
Python的paramiko模块能够连接远程主机,并在该主机上执行命令,和该主机之间进行文件传输.paramiko支持用明文密码登录远程主机和秘钥登录.使用之前要安装一下这个模块哈,pip inst ...
- 国际化实现之基于jquery
jQuery.i18n.properties是一款轻量级的jQuery国际化插件,能实现Web前端的国际化. jQuery.i18n.properties 采用 .properties 文件对 Jav ...
- JSON必知必会
知识点比较杂,简单的以列表形式罗列知识点 1.json是基于javascript对象字面量的,所以他们看起来很像.但是js对象字面量不需要给名称-值对中的名称两边加上双引号.而在JSON中,却是必要的 ...