原 python写算法题:leetcode: 115. Distinct Subsequences

class Solution(object):
    def numDistinct(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: int
        """

        cnt=[0]*len(t)

        for si,sc in enumerate(s):
            lastc=""
            rep=0
            for ti in xrange(len(t)-1,-1,-1):
                tc=t[ti]
                if tc==sc:
                    if ti==0:
                        cnt[ti]+=1
                    else:
                        cnt[ti]+=cnt[ti-1]
        return  cnt[-1]

 

上一篇:爱摸鱼的zhrt--CSUSTOJ-1021(01背包)


下一篇:1-4TL138/1808/6748-EthEVM开发板硬件说明书