My python code that return the correct answer


  • 0
    A

    This is my python code
    it's a exp time complexity, because it has a recursively

    class Solution:
    	# @param {string} s
    	# @param {string} t
    	# @return {integer}
    	result=0
    	def numDistinct(self, s, t):
    		list_s=' '.join(s).split(' ')#r a b b b i t
    		list_t=' '.join(t).split(' ')#r a b b   i t
    		self.rec_search(0,0,list_s,list_t)
    		print self.result
    		return self.result
    		
    	def rec_search(self,index_t,index_s,list_s,list_t):		
    		while index_s < len(list_s):
    			target=list_t[index_t]
    			if list_s[index_s] == target:
    				#print index_s,list_t[index_t]
    				if index_t+1<len(list_t):
    					self.rec_search(index_t+1,index_s+1,list_s,list_t)
    				else:
    					#print 'found finally a match'
    					self.result=self.result+1
    			index_s = index_s+1	
    		return 1

Log in to reply
 

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