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 be
makeArrayConsecutive2(statues) = 3.

Ratiorg needs statues of sizes 45 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的更多相关文章

  1. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  2. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  3. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  4. 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) + ...

  5. Code Signal_练习题_Array Replace

    Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem. Exam ...

  6. Code Signal_练习题_adjacentElementsProduct

    Given an array of integers, find the pair of adjacent elements that has the largest product and retu ...

  7. Code Signal_练习题_almostIncreasingSequence

    Given a sequence of integers as an array, determine whether it is possible to obtain a strictly incr ...

  8. Code Signal_练习题_All Longest Strings

    Given an array of strings, return another array containing all of its longest strings. Example For i ...

  9. Code Signal_练习题_arrayChange

    You are given an array of integers. On each move you are allowed to increase exactly one of its elem ...

随机推荐

  1. [ActionScript 3.0] UDP通信

    package com.controls.socket { import flash.events.DatagramSocketDataEvent; import flash.events.Event ...

  2. ubuntu14.0 安装 node v8.11.1(任意版本)

    由于众所周知的原因,通过node官网下载速度十分慢,我这里通过淘宝镜像安装 node8.11.1,其他版本同理. node版本淘宝镜像地址:https://npm.taobao.org/mirrors ...

  3. vector.clear()不能用来清零

    vector.clear()函数并不会把所有元素清零,笔者就曾经这样幻想过这个函数的作用,然而事实证明并不是. vector有两个参数,一个是size,表示当前vector容器内存储的元素个数,一个是 ...

  4. JS: RegExp(正则表达式)

    RegExp (包含ES2018新特性) 注意:本次所有代码都仅在Chrome 70中进行测试 正则表达式是什么? 正则表达式是用于匹配字符串中字符组合的模式.(mdn) 简单来说,正则表达式是用来提 ...

  5. POJ 1111

    #include<iostream> #define MAXN 30 using namespace std; char _m[MAXN][MAXN]; bool mark[MAXN][M ...

  6. A Node Influence Based Label Propagation Algorithm for Community detection in networks 文章算法实现的疑问

    这是我最近看到的一篇论文,思路还是很清晰的,就是改进的LPA算法.改进的地方在两个方面: (1)结合K-shell算法计算量了节点重重要度NI(node importance),标签更新顺序则按照NI ...

  7. JavaScript函数理解

    本文参考自简书javaScript之函数详解 这里从函数的构造函数开始. 在js中,函数都是对象,它们都是Function构造函数的实例.因此,类似Java中的对象,函数名可以理解为指向该Functi ...

  8. RabbitMQ : 几种Exchange 模式

    AMQP协议中的核心思想就是生产者和消费者隔离,生产者从不直接将消息发送给队列.生产者通常不知道是否一个消息会被发送到队列中,只是将消息发送到一个交换机.先由Exchange来接收,然后Exchang ...

  9. Mac 10.12允许任何来源

    sudo spctl --master-disable 然后即可设置.

  10. (转)python学习笔记4--数字类型与操作符

    原文:https://blog.csdn.net/lemonwyc/article/details/37558269 1. 同时赋值(Simultaneous Assignments) python支 ...