Post

leetcode(리트코드)-1886 Determine Whether Matrix Can Be Obtained By Rotation Equal(python)

leetcode 1886 - Determine Whether Matrix Can Be Obtained By Rotation 문제입니다.

1. 문제

https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/


2. Input , Output


3. 분류 및 난이도

Eazy 난이도 문제입니다.


4. 문제 해석

  • 숫자가 들어있는 정사각형이 주어집니다. 정사각형을 90도씩 돌렸을 때 target과 일치하면 True 아니면 False를 리턴합니다.

5. code

코드설명

python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:
    def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool:
        def rotate(mat):
            new = copy.deepcopy(mat)
            for i in range(len(mat)):
                for j in range(len(mat[i])):
                    new[j][len(mat[i]) - i - 1] = mat[i][j] 
            return new
        for i in range(4):
            if mat == target : 
                return True
            mat = rotate(mat)
        return False
        
    
    

6. 결과 및 후기, 개선점

필요시 c++로 짜드리겠습니다.

This post is licensed under CC BY 4.0 by the author.