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 ...
随机推荐
- Tree-669. Trim a Binary Search Tree
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that a ...
- ajax在php中应用实例
1,ajax分为$.ajax(),$.get(),$.post(),$.getJSON() 几种形式,实例如下: <html> <meta http-equiv="Cont ...
- python爬虫1——获取网站源代码(豆瓣图书top250信息)
# -*- coding: utf-8 -*- import requests import re import sys reload(sys) sys.setdefaultencoding('utf ...
- mariadb审计日志通过 logstash导入 hive
我们使用的 mariadb, 用的这个审计工具 https://mariadb.com/kb/en/library/mariadb-audit-plugin/ 这个工具一点都不考虑后期对数据的处理, ...
- css字体中英速查表
例1(小米米官网):font-family: "Arial","Microsoft YaHei","黑体","宋体",s ...
- [SqlServer] Error: 15023
Use DataBaseName go sp_change_users_login 'update_one', 'UserName', 'UserName' 恢复数据库后,添加用户,报错号15023 ...
- 指定nginx某个目录显示目录结构
1.修改配置文件/usr/local/nginx/conf/nginx.conf 指定目录,开启autoindex为on. location /study { autoindex on; } 2. 保 ...
- 微服务是"银弹"吗?
前言:所谓"银弹",本意是用金属银做成的子弹:在古老的传说里它是杀死狼人的有效武器.在著作<人月神话>也有描述.微服务是当前软件界流行的名词,那么它能成为像银弹一样厉害 ...
- 现代cpu的合并写技术对程序的影响
对于现代cpu而言,性能瓶颈则是对于内存的访问.cpu的速度往往都比主存的高至少两个数量级.因此cpu都引入了L1_cache与L2_cache,更加高端的cpu还加入了L3_cache.很显然,这个 ...
- jquery.lazyload插件实现图片延迟加载
jquery.lazyload是一个实现图片延迟加载的jQuery 插件,它可以延迟加载长页面中的图片.在浏览器可视区域外的图片在初始状态下不会被载入,直到用户将页面滚动到它们所在的位置. 1.引入j ...