TLE using BFS in python


#1

Why is this python solution giving TLE?

from collections import deque
class Solution:
    # @param A : integer
    # @return a strings
    def multiple(self, n):
        if n == 0:
            return 0
        q = deque()
        q.append(1)
        while len(q) > 0:
            x = q.popleft()
            if x % n == 0:
                return x
            if ( x * 10 ) % n == 0:
                return x * 10
            q.append(x * 10)
            if ( x * 10 + 1) % n == 0:
                return x * 10 + 1
            q.append(x * 10 + 1)