Longest Continuous Increasing Subsequence

    这道题为简单题

  题目:

    

  思路:

    设置三个变量,max_long 存储总的最大长度,l代表该值目前的最大长度,num主要用来比较列表的前后大小。如果i大于num那么l就一直加1.否则l就和max_long比较大小,l变为1,num更新为i值

  代码:

 1 class Solution:
 2     def findLengthOfLCIS(self, nums):
 3         """
 4         :type nums: List[int]
 5         :rtype: int
 6         """
 7         max_long = -float("inf")
 8         num = -float("inf")
 9         l = 0
10         for i in nums:
11             if i > num: l += 1
12             else:
13                 if l > max_long: max_long = l
14                 l = 1
15             num = i
16         return max(max_long, l)
时间: 2024-12-23 16:36:33

Longest Continuous Increasing Subsequence的相关文章

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] i

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] i

[LeetCode] 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] i

674. Longest Continuous Increasing Subsequence最长连续递增子数组

[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 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 t

Longest Continuous Increasing Subsequence LT674

Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 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

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

674. 最长连续递增序列 674. Longest Continuous Increasing Subsequence 题目描述 给定一个未经排序的整型数组,找到最长且连续的递增序列. Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 每日一算法2019/5/21Day 18LeetCode674. Longest Conti

LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)

题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 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 tho

[LC] 674. Longest Continuous Increasing Subsequence

Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 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

Longest Continuous Increasing Subsequence II

Description Given an integer matrix. Find the longest increasing continuous subsequence in this matrix and return the length of it. The longest increasing continuous subsequence here can start at any position and go up/down/left/right. Example Exampl

397. Longest Continuous Increasing Subsequence

Description Give an integer array,find the longest increasing continuous subsequence in this array. An increasing continuous subsequence: Can be from right to left or from left to right. Indices of the integers in the subsequence should be continuous