我不是要求任何人为我解决这个问题,我只需要一点推动,因为我没有从根本上知道从哪里开始.我所知道的是,我应该在此实现集合并进行排序.
编写一个方法longestSortedSequence,它返回整数列表中最长排序序列的长度.例如,如果名为list的变量存储以下值序列:
[1, 3, 5, 2, 9, 7, -3, 0, 42, 308, 17]
Run Code Online (Sandbox Code Playgroud)
然后调用:list.longestSortedSequence()将返回值4,因为它是此列表中最长排序序列的长度(序列-3,0,42,308).如果列表为空,则您的方法应返回0.请注意,对于非空列表,该方法将始终返回至少为1的值,因为任何单个元素都构成已排序的序列.
Assume you are adding to the ArrayIntList class with following fields:
public class ArrayIntList
{
private int[] elementData;
private int size;
// your code goes here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
624 次 |
| 最近记录: |