programming/Algorithm

2133. Check if Every Row and Column Contains All Numbers

Roien 2022. 1. 9.
반응형
class Solution:
    def checkValid(self, matrix: List[List[int]]) -> bool:
        n = len(matrix)

        for y in range(n):
            cnts = [0]*n

            for x in range(n):
                cnts[matrix[y][x] - 1] += 1

            if cnts != [1]*n:
                return False

        for x in range(n):
            cnts = [0]*n

            for y in range(n):
                cnts[matrix[y][x] - 1] += 1

            if cnts != [1]*n:
                return False

        return True

 

 

반응형

댓글