forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.rs
28 lines (28 loc) · 797 Bytes
/
Solution.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
impl Solution {
pub fn find_number_of_lis(nums: Vec<i32>) -> i32 {
let mut max_len = 0;
let mut ans = 0;
let n = nums.len();
let mut dp = vec![1; n];
let mut cnt = vec![1; n];
for i in 0..n {
for j in 0..i {
if nums[i] > nums[j] {
if dp[j] + 1 > dp[i] {
dp[i] = dp[j] + 1;
cnt[i] = cnt[j];
} else if dp[j] + 1 == dp[i] {
cnt[i] += cnt[j];
}
}
}
if dp[i] > max_len {
max_len = dp[i];
ans = cnt[i];
} else if dp[i] == max_len {
ans += cnt[i];
}
}
ans
}
}