LeetCode673

    技术2022-08-01  82

    class Solution { public int findNumberOfLIS(int[] nums) { int[] dp = new int[nums.length]; int[] count = new int[nums.length]; //base Arrays.fill(dp,1); Arrays.fill(count,1); int max = 0; //状态转移 for(int i = 0;i <nums.length;i++){ for(int j = 0;j < i ;j++){ if(nums[i] > nums[j]){ if(dp[j]+1>dp[i]){ dp[i]=dp[j]+1; count[i]=count[j]; } else if(dp[j]+1==dp[i]){ count[i]=count[j]+count[i]; } } } max = Math.max(max, dp[i]); } int ans = 0; for(int i = 0;i < nums.length;i++){ if(dp[i]==max){ ans = ans + count[i]; } } return ans; } }

     

    Processed: 0.018, SQL: 9