绳子问题
#include <stdio.h> int overrideMaxNum(int *points,int pointsNum,int L) { int maxNum=1,i=0,j=1; if(L<=0||points==NULL||pointsNum<=0)return 0; while(j<pointsNum) { while(j<pointsNum&&points[j]-points[i]<=L) { maxNum++; j++; } i++; j++; } return maxNum; } int main() { int points[10]={1,2,3,4,10,15,17,18,19,20}; printf("%d\n",overrideMaxNum(points,10,3)); return 0; }
一切源于对计算机的热爱