Simple Python Clean Pass

  • 0

    Simply iterate through the array and calculate the maxlength of an increasing subarray ending at index i: curlen. If that length is greater than your holdout variable, in this case maxlen, update maxlen

    def findLengthOfLCIS(self, nums):
            # edge case
            if len(nums) == 0:
                return 0
            maxlen = 1
            curlen= 1
            for i in range(1,len(nums)):
                if nums[i] > nums[i-1]:
                    curlen += 1
                    maxlen = max(maxlen, curlen)
                    curlen= 1
            return maxlen

Log in to reply

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