code test

Weirdo·2023년 6월 24일
0

-- arr
arr.append(a)
arr.remove(val)
arr.index(val)
[a for a in arr1 if a not in arr2]

-- dict
d = {}
d.keys(), d.values(), d.items() <- 괄호!!

-- set

-- heap
import heapq as hq
hq.heapify(arr)
hq.heappop(arr)
hq.heappush(arr, val)

-- etc
for i, x in enumerate(arr):
range(1, 4, 1) # (1, 2, 3)
max(a, b)
min(a, b)
global answer # 전역변수
[[0]*n for i in range(m)]

-- 최단거리, bfs
from collections import deque
def solution(maps):
answer = 0
n = len(maps)
m = len(maps[0])
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def bfs(x,y):
    q = deque()
    q.append((x,y))

    while q:
        x, y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if nx < 0 or ny < 0 or nx >= n or ny >= m:
                continue
            if maps[nx][ny] == 0:
                continue
            if maps[nx][ny] == 1:
                maps[nx][ny] = maps[x][y] + 1
                q.append((nx, ny))
    return maps[n-1][m-1]

if bfs(0,0) == 1:
    return -1
else:
    answer = bfs(0,0)

return answer
profile
Yeah, weirdos change the world

0개의 댓글