# 行易软件

 博客园 首页 新随笔 联系 订阅 管理

intList=[1,5,6,11,3,4,5,6,8,9]
maxLen=1
maxMaxLen=1
for i in range(len(intList)-1):
if intList[i]<intList[i+1] and intList[i+1]-intList[i]==1:
maxLen=maxLen+1
if(maxLen>maxMaxLen):
maxMaxLen=maxLen
else:
maxLen=1
print(maxMaxLen)

using System;

namespace Case4
{
class Program
{
static void Main(string[] args)
{
int[] intArray = { 1, 5, 6, 11, 3, 4, 5, 6, 8, 9 };
int maxLen = 1;
int maxMaxLen = 1;
for(int i=0;i<intArray.Length-1;i++)
{
if(intArray[i]<intArray[i+1] && intArray[i + 1] - intArray[i] == 1)
{
maxLen = maxLen + 1;
if (maxLen > maxMaxLen)
maxMaxLen = maxLen;
}
else
maxLen = 1;
}
Console.WriteLine(maxMaxLen);
}
}
}

#include <iostream>
using namespace std;

int main()
{
int intArray[] = { 1,5,6,11,3,4,5,6,8,9 };
int maxLen = 1;
int maxMaxLen = 1;
for (int i = 0; i < 9; i++)
{
if (intArray[i] < intArray[i + 1] && intArray[i + 1] - intArray[i] == 1)
{
maxLen++;
if (maxLen > maxMaxLen)
maxMaxLen = maxLen;
}
else
maxLen = 1;
}
cout << maxMaxLen << endl;
}

posted on 2022-07-22 19:21  行易软件技术团队  阅读(7)  评论(0编辑  收藏  举报