• LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)


    Given an unsorted array of integers, find the length of longest continuous increasing subsequence.

    Example 1:

    Input: [1,3,5,4,7]
    Output: 3
    Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. 
    Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4. 
    

    Example 2:

    Input: [2,2,2,2,2]
    Output: 1
    Explanation: The longest continuous increasing subsequence is [2], its length is 1. 
    

    Note: Length of the array will not exceed 10,000.


    题目标签:Array

      题目给了一个没有排序的nums array,让我们找到其中最长连续递增序列的长度。

      维护一个maxLen,每次遇到递增数字就tempLen++,遇到一个不是递增数字的话,就把tempLen 和maxLen 中大的保存到maxLen。

    Java Solution:

    Runtime beats 69.72% 

    完成日期:10/21/2017

    关键词:Array

    关键点:维护一个maxLen

     1 class Solution 
     2 {
     3     public int findLengthOfLCIS(int[] nums) 
     4     {
     5         if(nums == null || nums.length == 0)
     6             return 0;
     7         
     8         int maxLen = 0;
     9         int tempLen = 1;
    10         
    11         for(int i=1; i<nums.length; i++)
    12         {
    13             if(nums[i] <= nums[i-1])
    14             {
    15                 maxLen = Math.max(maxLen, tempLen);
    16                 tempLen = 1;
    17             }
    18             else
    19             {
    20                 tempLen++;
    21             }
    22             
    23         }
    24         
    25         return Math.max(maxLen, tempLen);
    26     }
    27 }

    参考资料:N/A

    LeetCode 题目列表 - LeetCode Questions List

  • 相关阅读:
    LD_DEBUG
    kernel相关前沿技术了解
    awk一次性分别赋值多个value给多个变量,速度对比
    google spanner
    python指定日期后加几天判断
    awk手册
    2017.12.28 现货黄金止盈复盘
    数据库和struts2的拦截器
    类和数据库的扫盲
    深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接(经典)
  • 原文地址:https://www.cnblogs.com/jimmycheng/p/7707617.html
Copyright © 2020-2023  润新知