博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Code Signal_练习题_Make Array Consecutive2
阅读量:7051 次
发布时间:2019-06-28

本文共 955 字,大约阅读时间需要 3 分钟。

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.

 

我的解答:

1 def makeArrayConsecutive2(statues):2     count = 03     for i in range(min(statues),max(statues)):4         if i not in statues:5             print(i)6             count += 17     return '总共需要以上%s个雕像'%count

 

膜拜大神:

def makeArrayConsecutive2(statues):    return max(statues) - min(statues) - len(statues) + 1
View Code

 

转载于:https://www.cnblogs.com/BlameKidd/p/9343304.html

你可能感兴趣的文章
NandFlash详述【转】
查看>>
Windows Builder(图形化界面的利器)For Eclipse 3.7
查看>>
每天要喝多少水
查看>>
request_mem_region 与 ioremap【转】
查看>>
指令级, ns级优化实例, 怎么做到调无可调
查看>>
Autodesk 2011系列新产品DevDay将于12月在北京/上海举行
查看>>
创建Visual studio项目模板 vstemplate关键点纪要
查看>>
SQL Server连接中三个常见的错误分析
查看>>
socket通信,server与多客户端通信
查看>>
[ACM_动态规划] ZOJ 1425 Crossed Matchings(交叉最大匹配 动态规划)
查看>>
LeetCode总结【转】
查看>>
枚举类型
查看>>
什么是 A 轮融资?有 B轮 C轮么?
查看>>
[CareerCup] 10.4 Find All Duplicates Elements 寻找所有的重复项
查看>>
jquery validationEngine的使用
查看>>
Symbian学习之路
查看>>
使用6to5,让今天就来写ES6的模块化开发!
查看>>
Windows 7 应用程序崩溃恢复
查看>>
(转载)iPhone开发视频教程 Objective-C部分 (51课时)
查看>>
Unity 5.1+ Assertion Library (断言库)
查看>>