I use a vector to store all the index i from S, which S[a0]...S[ai] = T[0]...T[i]

Here is my code:

```
#include <vector>
using namespace std;
class Solution {
public:
int numDistinct(string S, string T) {
if(S.length() < T.length())
{
return 0;
}
vector<int> end;
int count = 0;
for(int j = 0; j < S.length()-T.length()+1; j++)
{
if(T[0] == S[j])
{
end.push_back(j);
count++;
}
}
for(int i = 1; i < T.length(); i++)
{
int tc = 0;
for(int j = 0; j < count; j++)
{
for(int k = end[j]+1; k < S.length()-T.length()+i+1; k++)
{
if(T[i] == S[k])
{
end[tc] = k;
tc++;
}
}
}
count = tc;
}
return count;
}
};
```

runtime error when input: "aaaaaaaaaaaaa", "a"