Check if List<Int32> values are consecutive

One-liner, only iterates until the first non-consecutive element:

bool isConsecutive = !myIntList.Select((i,j) => i-j).Distinct().Skip(1).Any();

Update: a couple examples of how this works:

Input is { 5, 6, 7, 8 }
Select yields { (5-0=)5, (6-1=)5, (7-2=)5, (8-3=)5 }
Distinct yields { 5, (5 not distinct, 5 not distinct, 5 not distinct) }
Skip yields { (5 skipped, nothing left) }
Any returns false
Input is { 1, 2, 6, 7 }
Select yields { (1-0=)1, (2-1=)1, (6-2=)4, (7-3=)4 } *
Distinct yields { 1, (1 not distinct,) 4, (4 not distinct) } *
Skip yields { (1 skipped,) 4 }
Any returns true

* The Select will not yield the second 4 and the Distinct will not check it, as the Any will stop after finding the first 4.

Check if List<Int32> values are consecutive的更多相关文章

  1. error C4996: Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct

    使用VS13 跟  google protocbuf时出现了这个问题:真蛋疼,用别人的东西你就说不安全,用你自己的东西时你怎么不说不安全来着! 解决方案 在protoc   生成的头文件中加上 #pr ...

  2. check_mk 之 Check Parameters

    配置检测参数有几下方法 1. Creating manual checks instead of inventorized checks (using the variable checks). 2. ...

  3. android 官方文档 JNI TIPS

    文章地址  http://developer.android.com/training/articles/perf-jni.html JNI Tips JNI is the Java Native I ...

  4. NDK(5) Android JNI官方综合教程[JavaVM and JNIEnv,Threads ,jclass, jmethodID, and jfieldID,UTF-8 and UTF-16 Strings,Exceptions,Native Libraries等等]

    JNI Tips In this document JavaVM and JNIEnv Threads jclass, jmethodID, and jfieldID Local and Global ...

  5. [pytorch修改]npyio.py 实现在标签中使用两种delimiter分割文件的行

    from __future__ import division, absolute_import, print_function import io import sys import os impo ...

  6. Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册

    Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册 ctypes 是一个Python 标准库中的一个库.为了实现调用 DLL,或者共享库等C数据类型而设计.它可以把这 ...

  7. Android 性能优化(18)JNI优化:JNI Tips 提升性能技巧

    JNI Tips 1.In this document JavaVM and JNIEnv Threads jclass, jmethodID, and jfieldID Local and Glob ...

  8. An iOS zero-click radio proximity exploit odyssey

    NOTE: This specific issue was fixed before the launch of Privacy-Preserving Contact Tracing in iOS 1 ...

  9. 2016年最新mac下vscode配置golang开发环境支持debug

    网上目前还找不到完整的mac下golang环境配置支持,本人配置成功,现在整理分享出来. mac最好装下xcode,好像有依赖关系安装Homebrew打开终端窗口, 粘贴脚本执行/usr/bin/ru ...

随机推荐

  1. 经典数据结构与算法在经典软件(linux kernel)中的应用

    参考文章:Core Alorgithms deployed linux中的priority search tree数据结构研究 虚拟内存: 1.红黑树,管理与进程关联的vm_area_struct实例 ...

  2. java程序,在windows下设置为开机自启动

    1.制作可运行jar包 2.设置开机自动,后台运行,确保不关 一下这几个方法是我试过的,由于有不同的问题,以后慢慢总结 (1).制作bat文件,放在"启动"里面 (2).设置组策略 ...

  3. ECharts 散点图+百度地图(案例转载)

    转载来源:https://efe.baidu.com/blog/echarts-map-tutorial-2/ ECharts 实现地图散点图(下)  小红  2016-06-13  ECharts, ...

  4. Python学习日记(四) 集合和元祖

    元祖的特性:是一个只读列表.可以循环.可以切片,修改数据遵循'儿子'不能改但'孙子'可能可以改. iterable:可迭代对象(元祖.列表.字串.集合) 元祖宣告方式: tu = (1,2,3,['a ...

  5. uc/xi

    一个较为通用的定义为:嵌入式系统是对对象进行自动控制而使其具有智能化并可嵌入对象体系统中的专用计算机系统. 实时性:目前,嵌入式系统广泛应用于生产过程控制.数据采集.传输通信等场合,这些应用的共同特点 ...

  6. c# 日期和时间System.DateTime

  7. python 执行系统命令模块比较

    python 执行系统命令模块比较 1.os.system模块 仅仅在子终端运行命令,返回状态码,0为成功,其他为失败,但是不返回执行结果 如果再命令行下执行,结果直接打印出来 >>> ...

  8. Altium designer 如何将2D PCB转换成3D

    点击键盘数字键的3,即可,2键可以切换回2D效果,但是如果要看元器件的3D效果,那么元器件封装必须带有3D模型才行! 先按3切换到三维界面,然后按住shift不放,按鼠标右键调整视图角度.

  9. 微博MySQL优化之路

    数据库是所有架构中不可缺少的一环,一旦数据库出现性能问题,那对整个系统都回来带灾难性的后果.并且数据库一旦出现问题,由于数据库天生有状态(分主从)带数据(一般还不小),所以出问题之后的恢复时间一般不太 ...

  10. 《少年先疯队》第九次团队作业:Beta冲刺第一天

    1.1 今日完成任务情况 姚玉婷:酒店会员中房间管理功能的完善 马丽莎:登录功能测试文档的编写 张   琼:不同用户登录功能的测试,如管理员和会员 孙苗坤:登录功能测试用例的设计 1.2 明天任务安排 ...