Is this backtracking algo - wrong?


  • 0
    S

    It times out - is that expected?

            def backtracking(n):
                count = 0
                x = []
                q = []
                q.append(x)
                while len(q) > 0:
                    x = q.pop()
                    if len(x) == n:
                        count += 1
                    else:
                        for i in range(10):
                            y = x[:]
                            if i not in x:
                                y.append(i)
                                q.append(y)
                            elif len(y) < n and y[0] == 0:
                                count += 1
                
                return count
    

Log in to reply
 

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