[LeetCode] Valid Sudoku
来源:互联网 发布:覆盖表数据 编辑:程序博客网 时间:2024/06/15 18:25
问题:
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'
.
A partially filled sudoku which is valid.
分析:先分析行;再分析列;最后分析九宫格。前两个都好说,第三个要注意index。
代码:
class Solution {public:bool isValidSudoku(vector<vector<char> > &board) {// rowfor (int i = 0; i < 9; i ++) {vector<bool> numbers (9, false);for (int j = 0; j < 9; j ++) {char c = board[i][j];if (c == '.') continue;if (numbers[c - '0' - 1] == true)return false;elsenumbers[c - '0' - 1] = true;}}// colfor (int i = 0; i < 9; i ++) {vector<bool> numbers(9, false);for (int j = 0; j < 9; j ++) {char c = board[j][i];if (c == '.') continue;if (numbers[c - '0' - 1] == true)return false;elsenumbers[c - '0' - 1] = true;}}// ninesfor (int i = 0; i < 9; i ++) {vector<bool> numbers(9, false);for (int j = 0; j < 9; j ++) {int a = 3 * (i / 3) + j / 3; // rowint b = (j % 3) + (i % 3) * 3; // colchar c = board[a][b];if (c == '.') continue;if (numbers[c - '0' - 1] == true)return false;elsenumbers[c - '0' - 1] = true;}}return true;}};
0 0
- 【LeetCode】Valid Sudoku && Sudoku Solver
- [Leetcode]Sudoku Solver&&Valid Sudoku
- leetcode Valid Sudoku & Sudoku Solver
- LeetCode : Valid Sudoku
- [LeetCode]Valid Sudoku
- [leetcode] Valid Sudoku
- LeetCode-Valid Sudoku
- LeetCode Valid Sudoku
- LeetCode - Valid Sudoku
- LeetCode:Valid Sudoku
- leetcode-036:Valid Sudoku
- Leetcode: Valid Sudoku
- LeetCode题解:Valid Sudoku
- 【LeetCode】 Valid Sudoku
- Leetcode Valid Sudoku
- LeetCode | Valid Sudoku
- LeetCode Valid Sudoku
- [Leetcode] Valid Sudoku (Java)
- uva 702 The Vindictive Coach (DP)
- 构建自己的AngularJS,第一部分:Scope和Digest
- iOS Dev (21) 用 AVPlayer 播放一个本地音频文件
- sqlplus与sqlplusw
- java nio为什么是通道(三): 网络Channel
- [LeetCode] Valid Sudoku
- AngularJS:何时应该使用Directive、Controller、Service?
- ReadProcessMemory与WriteProcessMemory用例分析
- 多层嵌套的拖动排序组件
- Windows安全描述符SECURITY_DESCRIPTOR
- Android---Matrix类的使用
- Windows安全属性的设定
- printf中输出类型
- angularjs 失去焦点事件