本文共 677 字,大约阅读时间需要 2 分钟。
题目:
解答:
没有太看懂 看了网上的一些资料
http://www.cnblogs.com/ganganloveu/p/3836519.html
代码:
class Solution {public: int numDistinct(string S, string T) { int m = S.size(); int n = T.size(); vector> transArr(m+1, vector (n+1, 0)); for(int i = 0; i < m+1; i ++) transArr[i][0] = 1; for(int i = 1; i < m+1; i ++) { for(int j = 1; j < n+1; j ++) { if(S[i-1] == T[j-1]) transArr[i][j] = transArr[i-1][j-1]+transArr[i-1][j]; else transArr[i][j] = transArr[i-1][j]; } } return transArr[m][n]; }};