Code Signal

您所在的位置:网站首页 codesignal Code Signal

Code Signal

#Code Signal| 来源: 网络整理| 查看: 265

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.

 

我的解答:

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

 

膜拜大神:

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

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3