# Distinct Subsequences

#### 2.算法

    public int numDistinct(String S, String T)
{
if (S.length() == 0)
{
return 0;
}
if(T.length() == 0)
{
return 1;
}
int[][] res = new int[S.length() + 1][T.length() + 1];
res[0][0] = 1;
for (int i = 0; i < S.length(); i++)
{
res[i][0] = 1;
}
for (int i = 1; i <= S.length(); i++)
{
for (int j = 1; j <= T.length(); j++)
{
res[i][j] = res[i - 1][j];
if (S.charAt(i - 1) == T.charAt(j - 1))
{
res[i][j] += res[i - 1][j - 1];
}
}
}
return res[S.length()][T.length()];
}

    public int numDistinct(String S, String T)
{
if (S.length() == 0)
{
return 0;
}
if(T.length()==0)
{
return 1;
}
int[] res = new int[T.length() + 1];
res[0] = 1;
for (int i = 0; i < S.length(); i++)
{
for (int j = T.length() - 1; j >= 0; j--)
{
res[j + 1] = (S.charAt(i) == T.charAt(j) ? res[j] : 0) + res[j + 1];
}
}
return res[T.length()];
}

#### Leetcode Distinct Subsequences 解题报告

2014-02-23 21:51:17

#### LeetCode（115） Distinct Subsequences

2015-12-26 14:36:37

#### Distinct Subsequences 解题报告

2014-10-19 16:36:13

#### Distinct Subsequences -- LeetCode

2014-04-13 09:19:57

#### Distinct Subsequences（研究之后用自己的方法做的解释，易懂）

2016-11-28 20:52:23

#### LeetCode(115) Distinct Subsequences

2015-01-21 04:02:50

#### 【LeetCode】Distinct Subsequences 解题报告

2014-12-18 10:55:11

#### 115 Distinct Subsequences

2015-11-22 13:14:15

#### Distinct Subsequences(leetcode)

2014-11-08 16:04:16

#### [LeetCode][Java] Distinct Subsequences

2015-07-24 10:40:15