5 lines Python Solution O(nm) time O(n) space


  • 0
    S

    5 lines Python Solution O(nm) time O(n) space

    def numDistinct(self, s, t):
        dp = [1] + [0] * len(t)
        for (c, i) in ((cx, ix) for cx in s for ix in xrange(len(t), 0, -1)):
            if c == t[i-1]:
                dp[i] += dp[i-1]
        return dp[len(t)]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.