我的未排序数组是
string[] a = new string[] { "10", "22", "9", "33", "21", "50", "41", "60", "80" };
在这个数组中,
10,22,33,50,60,80
是按升序排列的,因此输出应该是6
。一般来说,我想要由数组元素构成的升序列表以第一个元素开始的最长可能长度。
我尝试过以下方法:
string[] a = new string[] { "10", "22", "9", "33", "21", "50", "41", "60", "80" };
List<int> res = new List<int>();
int arrLength = a.Length;
int i = 0;
int prev;
while (i < arrLength)
{
if (i < arrLength)
{
res.Add(Convert.ToInt32(a[i]));
prev = Convert.ToInt32(a[i]);
while (Convert.ToInt32(a[++i]) < prev) { }
}
}
int asdf = res.Count;
但未成功。
for (var j = i-1 ; j >= 0 ; j++)
。那应该是在递减j
吗? - John H1, 100
不是该数据集中的最长序列。1, 2, 3, 4, 5
才是。 - John H