nikunjsoni

1955

Aug 2nd, 2021
608
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int countSpecialSubsequences(vector<int>& nums) {
  4.         long long int dp[3];
  5.         memset(dp, 0, sizeof dp);
  6.         long long mod = int(1e9)+7;
  7.         for(int i=0; i<nums.size(); i++){
  8.             int a = nums[i];
  9.             if(a == 0)
  10.                 dp[a] = (2LL*dp[a]+1)%mod;
  11.             else
  12.                 dp[a] = (2LL*dp[a]+dp[a-1])%mod;
  13.         }
  14.         return dp[2];
  15.     }
  16. };
RAW Paste Data