diff options
Diffstat (limited to 'other/valid_sudoku.cpp')
-rw-r--r-- | other/valid_sudoku.cpp | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/other/valid_sudoku.cpp b/other/valid_sudoku.cpp deleted file mode 100644 index 0843d67..0000000 --- a/other/valid_sudoku.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "leetcode.h" -#include <vector> - -class Solution { -public: - bool isValidSudoku(vvd(char) & board) { - vector<set<char>> rows(9), cols(9), blck(9); - for (int i = 0; i < 9; i++) - for (int j = 0; j < 9; j++) - if (board[i][j] != '.') { - int m = board[i][j], n = (i / 3) * 3 + j / 3; - if (!rows[i].emplace(m).second) // rows - return false; - if (!cols[j].emplace(m).second) // columns - return false; - if (!blck[n].emplace(m).second) // blocks - return false; - } - return true; - } -}; - -int main() { - Solution obj; - vvd(char) board = {{'8', '3', '.', '.', '7', '.', '.', '.', '.'}, - {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, - {'.', '9', '8', '.', '.', '.', '.', '6', '.'}, - {'8', '.', '.', '.', '6', '.', '.', '.', '3'}, - {'4', '.', '.', '8', '.', '3', '.', '.', '1'}, - {'7', '.', '.', '.', '2', '.', '.', '.', '6'}, - {'.', '6', '.', '.', '.', '.', '2', '8', '.'}, - {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, - {'.', '.', '.', '.', '8', '.', '.', '7', '9'}}; - if (obj.isValidSudoku(board)) - cout << "true"; - else - cout << "false"; -} |