I got aTLE but i don't know how to solve it


  • 0
    E

    class Solution:
    # @param s, a string
    # @param dict, a set of string
    # @return a boolean
    result = ""

    def wordBreak(self, s, dict):
        if s == None or dict == None:return s
        
        for x in dict:
            if x in s:
                temp = s.split(x)
                if temp[0] != '':
                    pass
                else:
                    Solution.result += (x + ' ') 
                    length = len(x)
                    temp2 = s[length:]
                    self.wordBreak(temp2, dict)
            else:pass
        
        return Solution.result

Log in to reply
 

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