<qiyuangong>286_Walls_and_Gates_1.py
def wallsAndGates( rooms):
    direction = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    m = len(rooms)
    if m == 0:
        return
    n = len(rooms[0])
    q = []
    for row in range(m):
        for col in range(n):
            if rooms[row][col] == 0:
                q.append((row, col))
    
    while len(q) > 0:
        point = q.pop(0)
        row, col = point[0], point[1]
        for d in direction:
            r = row + d[0]
            c = col + d[1]
            if r < 0 or c < 0 or r >= m or c >= n or rooms[r][c] != 2147483647:
                continue
            rooms[r][c] = rooms[row][col] + 1
            q.append((r, c))
def sample_funcname ( var_0 ) :
    var_3 = [ ( 0 , 1 ) , ( 1 , 0 ) , ( 0 , - 1 ) , ( - 1 , 0 ) ]
    var_5 = len ( var_0 )
    if var_5 == 0 :
        return
    var_6 = len ( var_0 [ 0 ] )
    var_7 = [ ]
    for var_9 in range ( var_5 ) :
        for var_10 in range ( var_6 ) :
            if var_0 [ var_9 ] [ var_10 ] == 0 :
                var_7.append ( ( var_9 , var_10 ) )
    while len ( var_7 ) > 0 :
        var_13 = var_7.pop ( 0 )
        var_9 , var_10 = var_13 [ 0 ] , var_13 [ 1 ]
        for var_14 in var_3 :
            var_15 = var_9 + var_14 [ 0 ]
            var_16 = var_10 + var_14 [ 1 ]
            if var_15 < 0 or var_16 < 0 or var_15 >= var_5 or var_16 >= var_6 or var_0 [ var_15 ] [ var_16 ] != 2147483647 :
                continue
            var_0 [ var_15 ] [ var_16 ] = var_0 [ var_9 ] [ var_10 ] + 1
            var_7.append ( ( var_15 , var_16 ) )
