[알고리즘] 2차원 배열 회전

·
Algorithm
Rotate MatrixProblem:Given a 2D array (matrix) of n × n elements, rotate the matrix by 90 degrees clockwise.Example:Input:[ [1, 2, 3], [4, 5, 6], [7, 8, 9]] Output:[ [7, 4, 1], [8, 5, 2], [9, 6, 3]] 해설최상단에 있는 1,2,3 은 배열의 가장 끝번호로 이동한다. 배열로 보면 arr[0][0], arr[0][1], arr[0][2] ➡️ arr[0][끝], arr[1][끝], arr[2][끝] ... 와 같다. 위 문장은 for 문을 통해 arr[i][j] ➡️ arr[j][N - 1 - i] 이 될 것이다. 즉, 행의 값은 열로 옮겨지고..