Python simple code 218 ms


  • 0

    Solution by my own. Welcome to any implement or question. Key point is 'range(len(s),i,-1)' instead of 'range(i+1,len(s)+1)'

    class Solution(object):

    def minCut(self, s):
        cache = [False] * len(s)
        r = [0]
        for _ in range(len(s)+1):
            nr = []
            for i in r:
                for x1 in range(len(s),i,-1):
                    if s[i:x1][::-1] == s[i:x1]: 
                        if x1 == len(s): return _
                        elif cache[x1] == False: 
                            nr.append(x1)
                            cache[x1] = True
            r = nr
    

    """"


Log in to reply
 

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