Getting TLE on Dijkstra (Actually BFS but got idea from dij.)


#1

Any suggestions will be really helpful

class Solution:
# @param A : integer
# @return a strings

def dijkstra(self,n):
    from collections import deque
    deq=deque()
    deq.append(1)
    while deq:
        u=deq.popleft()
        if not u%n:
            return str(u)
        k=u*10
        deq.append(k)
        deq.append(k+1)

def multiple(self, A):
    return self.dijkstra(A)