zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    【Jenkins】jenkins 配置腾讯企业邮箱
    Monkey 用户指南(译)
    Windows,easygui 安装
    python笔记:list--pop与remove的区别
    递归--Java_汉诺塔
    appium安装 For windows
    【web开发--js学习】functionName 如果是一个属性值,函数将不会被调用
    python爬取煎蛋网图片
    pv&pvc
    docker
  • 原文地址:https://www.cnblogs.com/jimmycheng/p/7707617.html
Copyright © 2011-2022 走看看