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