给定一个没有排序的整数数组,找到最长且连续递增的子序列,并返回该序列的长度。

    序列的下标是连续的

    1. public class MaxIncrementSequence {
    2. public static void main(String[] args) {
    3. System.out.println(findLength(new int[]{1, 2, 3, 2, 3, 4, 3, 4, 5, 6, 7}));
    4. }
    5. private static int findLength(int[] nums) {
    6. int start = 0;
    7. int max = 0;
    8. for (int i = 1; i < nums.length; i++) {
    9. if (nums[i] <= nums[i - 1]) {
    10. start = i;
    11. }
    12. max = Math.max(max, i - start + 1);
    13. }
    14. return max;
    15. }
    16. }