Advertisement
Singasking

Untitled

Jul 21st, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int findNumberOfLIS(vector<int>& nums) {
  4. vector<int> dp(nums.size()+1,1);
  5. int increasingSeqCount=1;
  6. int maxLen=1;
  7. for(int i=0;i<nums.size();i++) {
  8. for(int j=0;j<i;j++) {
  9. if(nums[j]<nums[i] ) {
  10. maxLen = max(maxLen,dp[i]);
  11. if(dp[j]+1>dp[i]) {
  12. dp[i] = dp[j]+1;
  13. }
  14. if(dp[j]+1>maxLen) {
  15. increasingSeqCount=1;
  16. maxLen =dp[j]+1;
  17. } else if(dp[j]+1==maxLen) {
  18. increasingSeqCount+=1;
  19. }
  20. }
  21. }
  22. }
  23.  
  24. if(maxLen==1) return nums.size();
  25. return increasingSeqCount;
  26.  
  27. }
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement