Check if List values are consecutive

前端 未结 12 1835
悲&欢浪女
悲&欢浪女 2021-02-01 05:46
List dansConList = new List();
dansConList[0] = 1;
dansConList[1] = 2;
dansConList[2] = 3;

List dansRandomList = new List

        
12条回答
  •  长情又很酷
    2021-02-01 06:33

    Here is a C version code, I think it's easy to rewrite it in other language based on the logical.

    int isConsecutive(int *array, int length) {
         int i = 1;
         for (; i < length; i++) {
              if (array[i] != array[i - 1] + 1)
                  return 0; //which means false and it's not a consecutive list
         }
    
         return 1;
    }
    

提交回复
热议问题