LeetCode-674:Longest Continuous Increasing Subsequence (最长连续增序列)

来源:互联网 发布:淘宝客服兼职工作 编辑:程序博客网 时间:2024/05/16 17:20

Question

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

Example 1:

Input: [1,3,5,4,7]Output: 3Explanation: 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: 1Explanation: The longest continuous increasing subsequence is [2], its length is 1. 

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

问题解析:

给定数组,找到其中最长的连续递增的子数组序列,连续相等不算递增。

Answer

Solution 1:

遍历实现。

  • 题目比较简单,通过记录最小和最大索引位置和当前最大长度,遍历实现即可。
class Solution {    public int findLengthOfLCIS(int[] nums) {        if (nums == null || nums.length == 0) return 0;        int maxlength = 1;        int left = 0;        int right = 0;        for (int i = 0; i < nums.length-1; i++){            if (nums[i] < nums[i+1]){                right++;                maxlength = Math.max(maxlength, right-left+1);            }else{                left = right = i+1;            }        }        return maxlength;    }}
  • 时间复杂度:O(n),空间复杂度:O(1)
阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 请点此进入新址33220九肖 94地址永久发布页 侄子偷婶娘电影 年轻嫂嫂5完整中文字幕版 漂亮伯母到我家来住宿电影 年轻的岳毋2018中文 年轻的婶子在线播放1080p 中文全彩再伯母家大汗淋漓电影 我和二伯母愉情电子书 与邻居我和邻居阿夷愉情 我和农村留守妇女愉情真实故事 西游记 之三插王母 水原梨花母友人中文字幕 屁孩睡走叔母3中文字幕 林氏集团和伯母 太监跟娘娘私通小说 欧阳锋跟他大嫂私通在哪一集 太监跟娘娘私通 我和唐伯母在厨房 同居了大嫂中文字幕 年轻的后妈1完整高清免费观看 漂亮的老婆在线中字幕 母亲今晚让你入个够免费阅读 漂亮的续母韩国电影 我的漂亮后妈201电影 朋友的母亲3字幕中文翻译 邻居喝醉我睡了他老婆 白天当儿子晚上当丈夫视频 二姑装睡让我 白天是儿子晚上是丈夫阅读 老公去世和儿儿子做 白天是我妈晚上是老婆 蜜母耻中文字幕下载 友人之母中文字幕视频 友人之母增尾彩 内田春菊友人之母 母友人佐佐木明希中文字幕 友人之母谷源希美西瓜 母友人三浦中文字幕在线播放 大嫂被逼无奈和小叔传种接代 母友人作品封面