Python Solution


  • 0
    class Solution(object):
        def findNumberOfLIS(self, nums):
            ans = [0, 0]
            l = len(nums)
            dp = collections.defaultdict(list)
            for i in range(l):
                dp[i] = [1, 1]
            for i in range(l):
                for j in range(i):
                    if nums[i] > nums[j]:
                        if dp[j][0] + 1 > dp[i][0]:
                            dp[i] = [dp[j][0] + 1, dp[j][1]]
                        elif dp[j][0] + 1 == dp[i][0]:
                            dp[i] = [dp[i][0], dp[i][1] + dp[j][1]]
            for i in dp.keys():
                if dp[i][0] > ans[0]:
                    ans = [dp[i][0], dp[i][1]]
                elif dp[i][0] == ans[0]:
                    ans = [dp[i][0], ans[1] + dp[i][1]]
            return ans[1]
    

Log in to reply
 

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