FTPrep, 37 Sukodu Solver
来源:互联网 发布:淘宝评价晒图怎么删除 编辑:程序博客网 时间:2024/06/03 11:18
TODO: the explanation for the flow
1, recursive function: 3 key points
2, naming is important for logic and debugging, always having a good variable name
3, one-time bug free is left to do, first time is xxx minute and second
代码:
public class Solution { public void solveSudoku(char[][] board) { helper(board, 0, 0); } private boolean helper(char[][] board, int row, int col){ if(col==9) return helper(board, row+1, 0); if(row==9) return true; if(board[row][col]=='.'){ for(int k=1; k<=9; k++){ board[row][col] = (char)('0'+ k); if(isValid(board, row, col, board[row][col])){ if(helper(board, row, col+1)) return true; } board[row][col]='.'; } return false; } else return helper(board, row, col+1); } private boolean isValid(char[][] board, int i, int j, char ch){ for(int col=0; col<board[0].length; col++){ if(col!=j&& ch==board[i][col]) return false; } for(int row=0; row<board.length; row++){ if(row!=i&& ch==board[row][j]) return false; } for(int row=i/3*3; row<i/3*3 +3; row++){ for(int col=j/3*3; col<j/3*3+3; col++){ if((row!=i || col!=j) && ch==board[row][col]) return false; } } return true; }}
阅读全文
0 0
- FTPrep, 37 Sukodu Solver
- Sukodu Solver(深搜)
- Valid Sukodu
- Leetcode 37 Sudoku Solver
- Leetcode 37: Sudoku solver
- [leetcode 37] Sudoku Solver
- LeetCode(37) Sudoku Solver
- leetcode 37:Sudoku Solver
- leetcode 37: Sudoku Solver
- 37Sudoku Solver
- Leetcode #37 Sudoku Solver
- leetcode-37 Sudoku Solver
- leetcode 37:Sudoku Solver
- LeetCode 37: Sudoku Solver
- LeetCode 37 - Sudoku Solver
- LeetCode(37)-Sudoku Solver
- leetcode 37 Sudoku Solver
- LeetCode 37 Sudoku Solver
- 必须拼命,才能对得起老爸老妈的辛劳!
- 编写Java程序,将能够被13整除的前400个数字存储到数组中
- 萌新的linux之旅21
- Linked List-----25. Reverse Nodes in k-Group
- 东南大学 崇志宏:我们在折腾什么?
- FTPrep, 37 Sukodu Solver
- 并查集 [POI2007]洪水pow
- FFmpeg+MinGW+VS2013
- 【二分图匹配入门专题1】C
- 图论专题 菜肴制作 矩阵游戏 魔法森林 飞行路线
- 我工作过的系
- BZOJ 3505 数三角形
- 差分约束+tarjin [Poi2012]Festival
- [POI2007]洪水pow 并查集