Skip to content

Commit 94e985a

Browse files
committed
Again same thing as yesterday , difficult to understand easy to code
1 parent 53eafb4 commit 94e985a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution {
2+
public:
3+
int findNumberOfLIS(vector<int>& nums)
4+
{
5+
vector<int> dp(nums.size(),1);
6+
vector<int> count(nums.size(),1);
7+
int max1 = 1;
8+
9+
for(int i = 1;i<nums.size();i++)
10+
{
11+
for(int j = 0;j<i;j++)
12+
{
13+
if(nums[i]>nums[j])
14+
{
15+
if(dp[j]+1>dp[i])
16+
{
17+
dp[i] = dp[j]+1;
18+
count[i] = count[j];
19+
}
20+
else if(dp[i]==dp[j]+1)
21+
{
22+
count[i] += count[j];
23+
}
24+
}
25+
}
26+
max1 = max(max1,dp[i]);
27+
}
28+
29+
int toreturn = 0;
30+
31+
for(int i = 0;i<nums.size();i++)
32+
{
33+
if(dp[i]==max1)
34+
{
35+
toreturn += count[i];
36+
}
37+
}
38+
return toreturn;
39+
}
40+
};

0 commit comments

Comments
 (0)