Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int findNumberOfLIS(vector<int>& nums) {
- vector<int> dp(nums.size()+1,1);
- int increasingSeqCount=1;
- int maxLen=1;
- for(int i=0;i<nums.size();i++) {
- for(int j=0;j<i;j++) {
- if(nums[j]<nums[i] ) {
- maxLen = max(maxLen,dp[i]);
- if(dp[j]+1>dp[i]) {
- dp[i] = dp[j]+1;
- }
- if(dp[j]+1>maxLen) {
- increasingSeqCount=1;
- maxLen =dp[j]+1;
- } else if(dp[j]+1==maxLen) {
- increasingSeqCount+=1;
- }
- }
- }
- }
- if(maxLen==1) return nums.size();
- return increasingSeqCount;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement