My solution with c++ in o(t*s) time and o(t) space


  • 1
    S
     int numDistinct(string s, string t) {
        int res=0;
        int i,j,k;
        vector<int> counter(t.size(),0);
        for(i=0;i<s.size();i++){
            for(j=t.size()-1;j>=0;j--){
                if(t[j]==s[i]){
                    if(j) counter[j]+=counter[j-1];
                    else counter[j]++;
                }
            }
        }
        return counter.back();
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.