跳过正文
  1. leetcode 题解/

674_最长连续递增序列

·55 字·1 分钟

类型:数组

    1. 最长连续递增序列 💚

    https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/

    ❓ 找出未排序数组 nums 的最长连续递增子序列,返回序列长度。

    💡 贪心

    class Solution:
        def findLengthOfLCIS(self, nums: List[int]) -> int:
            ans = 0
            n = len(nums)
            start = 0
    
            for i in range(n):
                if i > 0 and nums[i] <= nums[i - 1]:
                    start = i
                ans = max(ans, i - start + 1)
    
            return ans

    时间复杂度:O(n),空间复杂度:O(1)