상위 150개 인터뷰쉬움

이미지 회전

'이미지 회전' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

이미지를 나타내는 n x n 2D 행렬이 주어지면 이미지를 90도(시계 방향) 회전합니다.

이미지를 그 자리에서 회전해야 합니다. 즉, 입력 2D 매트릭스를 직접 수정해야 합니다. 다른 2D 매트릭스를 할당하고 회전을 수행하지 마십시오.

행렬을 제자리에서 회전하고 반환하는 rotate(matrix: list) -> list 함수를 구현하세요.

제약
  • n == matrix.length == matrix[i].length
  • 1 <= n <= 20
  • -1000 <= matrix[i][j] <= 1000

Example 1
Input
[[1,2,3],[4,5,6],[7,8,9]]
Output
[[7,4,1],[8,5,2],[9,6,3]]
Explanation

The matrix is rotated 90 degrees clockwise. The first column [1,4,7] becomes the first row [7,4,1] reversed.

Example 2
Input
[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output
[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Explanation

Each layer of the 4x4 matrix is rotated 90 degrees clockwise.

Need a Hint?
세트나 힙과 같은 수학 및 기하학 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.