전체 글 379

코딩테스트를 위한 JavaScript 알고리즘

bfsstart - [x, y, time]end - [x, y]board - 이차원 배열 (O - 이동 가능 / X - 불가능)visited - 방문 기록 (방문 확인 1 / 미방문 0)start에서 end까지 가는 시간 계산시작시간은 start의 세번째 인자 기준으로 도달하지 못하는 경우 -1const bfs = (start, end, board) => { const dx = [-1, 1, 0, 0] const dy = [0, 0, -1, 1] const visited = Array.from({ length: board.length }, () => Array(board[0].length).fill(0)) visited[start[0]][start[1]] = 1 const qu..

Algorithm/theory 2025.01.27