葉林
Linked with GitHub
# LeetCode - 0036. Valid Sudoku ### 題目網址:https://leetcode.com/problems/valid-sudoku/ ###### tags: `LeetCode` `Medium` `陣列` ```cpp= /* -LeetCode format- Problem: 36. Valid Sudoku Difficulty: Medium by Inversionpeter */ class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { static int row, column, counts, i, j, k, l; for (i = 0; i < 9; ++i) { for (j = 0, counts = 0; j < 9; ++j) if (board[i][j] != '.') { if (counts & (1 << (board[i][j] - '0'))) return false; counts |= (1 << (board[i][j] - '0')); } for (j = 0, counts = 0; j < 9; ++j) if (board[j][i] != '.') { if (counts & (1 << (board[j][i] - '0'))) return false; counts |= (1 << (board[j][i] - '0')); } } for (i = 0; i < 3; ++i) { row = i * 3; for (j = 0; j < 3; ++j) { column = j * 3; for (k = 0, counts = 0; k < 3; ++k) for (l = 0; l < 3; ++l) if (board[row + k][column + l] != '.') { if (counts & (1 << (board[row + k][column + l] - '0'))) return false; counts |= (1 << (board[row + k][column + l] - '0')); } } } return true; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up