连续数字
来源:互联网 发布:linux基本命令的使用 编辑:程序博客网 时间:2024/04/30 10:19
描述:
写一个方法consecutive(arr),参数为一个整数数组,返回这个数组中最小值到最大值之间所需连续数字的个数(不包含数组中已有的数字)
例如:
如果数组为 [4, 8, 6] 那么应该输出2。 因为4到8之间还需要两个数字(5,7)才能把这个数组变成连续数字。参数数组中每个数字都是唯一的。
MyCode:
using System.Linq;public class Kata{ public static int Consecutive(int[] arr) { if(arr.Length < 2) return 0; int x = arr.Min(); int count = 0; while(x <= arr.Max()) { x++; count++; } return (count - arr.Length); }}
CodeWar:
using System.Linq;public class Kata{ public static int Consecutive(int[] arr) { return arr.Length==0 ? 0 : arr.Max()-arr.Min()-arr.Length+1; }}
0 0
- 连续数字
- 分隔连续数字
- 输出连续数字
- 一个连续数字
- dfs分离连续数字
- 连续英文、数字换行
- 连续数字最大乘积
- 最大连续数字长度
- sql找出连续日期和连续数字
- 合并连续数字的算法
- 数组特殊处理(连续数字)
- 正则匹配连续三个数字
- vim生成连续数字列
- 数字连续的子数组
- CONNECT BY 构造连续数字
- 最长连续数字子串
- oracle产生连续的数字
- 挑选缺少的连续数字
- Unity 3D中的内存管理
- 看完这篇文章,你会对H5页面有一个全面的认识
- Android Studio调试技巧
- 通过系统时间判断 上下午
- sdut oj 3665 Feed the monkey(dp)
- 连续数字
- 页面滚动时的位置:为了兼容浏览器,封装自己的scrollTop和scrollLeft(内含“怪异模式”)
- altium designer PCB 屏蔽DRC报错
- Xtreme 10.0 - Painter's Dilemma
- 442. Find All Duplicates in an Array
- 一个命令行接口的实现
- App后台开发运维和架构实践学习总结(2)——RESTful API设计技巧
- 简单易懂 MVP 模式
- netstat