파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 11. 23. 23:45

https://leetcode.com/problems/valid-sudoku/

 

Valid Sudoku - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

그냥 무식하게 풀면 됨.
오타 때문에 3번 틀림 ㅠ_ㅠ

class Solution:
    def isValidSudoku(self, board: List[List[str]]) -> bool:
        for i in range(9):
            check = [0 for _ in range(10)]
            for j in range(9):
                if board[i][j] == '.':
                    continue
                if check[int(board[i][j])] > 0:
                    return False
                check[int(board[i][j])] += 1
        
        for i in range(9):
            check = [0 for _ in range(10)]
            for j in range(9):
                if board[j][i] == '.':
                    continue
                if check[int(board[j][i])] > 0:
                    return False
                check[int(board[j][i])] += 1
        
        for x, y in [[0, 0], [3, 0], [6, 0], [0, 3], [3, 3], [6, 3], [0, 6], [3, 6], [6, 6]]:
            check = [0 for _ in range(10)]
            for i in range(x, x+3):
                for j in range(y, y+3):
                    if board[j][i] == '.':
                        continue
                    if check[int(board[j][i])] > 0:
                        return False
                    check[int(board[j][i])] += 1
                    
        return True
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.11.25
Today's Challenge  (0) 2022.11.24
Today's Challenge  (0) 2022.11.22
Today's Challenge  (0) 2022.11.21
Today's Challenge  (0) 2022.11.20
Comments