We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9fe5b61 commit 4476ec2Copy full SHA for 4476ec2
solution/0673.Number of Longest Increasing Subsequence/Solution.java
@@ -0,0 +1,33 @@
1
+class Solution {
2
+ public int findNumberOfLIS(int[] nums) {
3
+ if (nums == null || nums.length == 0) {
4
+ return 0;
5
+ }
6
+ int n = nums.length;
7
+ int[] dp = new int[n];
8
+ int[] f = new int[n];
9
+ Arrays.fill(dp, 1);
10
+ Arrays.fill(f, 1);
11
+ int max = 0;
12
+ for (int i = 0; i < n; ++i) {
13
+ for (int j = 0; j < i; ++j) {
14
+ if (nums[i] > nums[j]) {
15
+ if (dp[j] + 1 > dp[i]) {
16
+ dp[i] = dp[j] + 1;
17
+ f[i] = f[j];
18
+ } else if (dp[j] + 1 == dp[i]) {
19
+ f[i] += f[j];
20
21
22
23
+ max = Math.max(max, dp[i]);
24
25
+ int res = 0;
26
27
+ if (dp[i] == max) {
28
+ res += f[i];
29
30
31
+ return res;
32
33
+}
0 commit comments