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

  • 0

    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] != '':
                    Solution.result += (x + ' ') 
                    length = len(x)
                    temp2 = s[length:]
                    self.wordBreak(temp2, dict)
        return Solution.result

Log in to reply

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