Solution for Longest Continuous Subsequence Problem


  • 0
    S
    class Solution:
        def findLengthOfLCIS(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if not nums:
                return 0
            count = []
            for k in range(len(nums)):
                count.append(1)
            j = 0
            for i in range(len(nums)-1):
                if nums[i]<nums[i+1]:
                    count[j] = count[j]+1
                else:
                    j = j+1
            return max(count)
    

  • 0
    C
    class Solution(object):
        def findLengthOfLCIS(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if nums == []:
                return 0
            d_max = 1
            d = 1
            interval = 32
            while (len(nums) - 1) % interval != 0:
                nums.append(nums[-1])
            for i in range(0, len(nums)-interval, interval):
                for j in range(interval):
                    if nums[i+j] < nums[i+j+1]:
                        d += 1
                    else:
                        if d_max < d:
                            d_max = d
                        d = 1
    
            return max(d, d_max)  
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.