-
행렬 테두리 회전하기코딩 테스트/Level 2 2021. 5. 1. 06:15반응형
행렬 테두리 회전하기
2021 Dev-Matching: 웹 백엔드 개발자(상반기)
226명 완료programmers.co.kr/learn/courses/30/lessons/77485
def solution(rows, columns, queries): matrix = [[row * columns + column + 1 for column in range(columns)] for row in range(rows)] answer = [] for x1, y1, x2, y2 in queries: x = x1 - 1 y = y1 - 1 prev_num = matrix[x + 1][y] min_value = float('inf') for y in range(y1 - 1, y2): prev_num, min_value = exchange(matrix, x, y, prev_num, min_value) for x in range(x1, x2): prev_num, min_value = exchange(matrix, x, y, prev_num, min_value) for y in range(y2 - 2, y1 - 2, -1): prev_num, min_value = exchange(matrix, x, y, prev_num, min_value) for x in range(x2 - 2, x1 - 1, -1): prev_num, min_value = exchange(matrix, x, y, prev_num, min_value) answer.append(min_value) return answer def exchange(matrix, x, y, prev_num, min_value): temp = matrix[x][y] matrix[x][y] = prev_num prev_num = temp if matrix[x][y] < min_value: min_value = matrix[x][y] return prev_num, min_value
반응형