this solution is almost the same as https://discuss.leetcode.com/topic/9488/easy-to-understand-dp-in-java/2 except it uses O(N) space where N is the length of input t.length().

If you look at the solution proposed by https://discuss.leetcode.com/topic/9488/easy-to-understand-dp-in-java/2, you can find that we do not really need to keep the entire mem table. Instead, we only need to keep the previous row.

```
public int numDistinct(String s, String t) {
int[] mem = new int[t.length()];
int prev = 1;
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < t.length(); j++) {
if (j == 0) prev = 1;
int newPrev = mem[j];
if (s.charAt(i) == t.charAt(j)) {
mem[j] = mem[j] + prev;
}
prev = newPrev;
}
}
return mem[t.length() - 1];
}
```