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 db8ce78 commit a166a70Copy full SHA for a166a70
numberOfLIS.cpp
@@ -0,0 +1,27 @@
1
+class Solution {
2
+public:
3
+ int findNumberOfLIS(vector<int>& nums) {
4
+ int n = nums.size();
5
+ vector <int> len(n, 1), cnt(n, 1);
6
+ int lis = 1;
7
+ for(int i = 1; i < n; i++){
8
+ for(int j = 0; j < i; j++){
9
+ if(nums[i] > nums[j]){
10
+ if(len[j] + 1 > len[i]){
11
+ len[i] = len[j] + 1;
12
+ cnt[i] = cnt[j];
13
+ }
14
+ else if(len[j] + 1 == len[i]){
15
+ cnt[i] += cnt[j];
16
17
18
+ lis = max(lis, len[i]);
19
20
21
+ int ans = 0;
22
+ for(int i = 0; i < n; i++){
23
+ if(len[i] == lis)ans += cnt[i];
24
25
+ return ans;
26
27
+};
0 commit comments