Couldn't find a simpler Python solution than this


  • 0
    P

    O(m*n) time, O(m) space. Beats 98%. For a leetcode hard, the answer can be pretty simple.

    def numDistinct(self, s, t):
        state = [1]+[0]*len(t)
        for c in s:
            new = state[:]
            for i,k in enumerate(t):
                if k==c: new[i+1] += state[i]
            state = new
        return state[-1]
    

Log in to reply
 

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