public int numDistinct(String s, String t) {
        if (s == null || t == null) return 0;
        int[][] dp = new int[t.length() + 1][s.length() + 1];
        for (int j = 0; j <= s.length(); ++j) dp[0][j] = 1; // t is empty
        for (int i = 0; i < t.length(); ++i) {
            for (int j = 0; j < s.length(); ++j) {
                dp[i + 1][j + 1] = dp[i + 1][j] + (t.charAt(i) == s.charAt(j) ? dp[i][j] : 0);
            }
        }
        return dp[t.length()][s.length()];
    }