解題思路: 大水題, 依規則,橫向確認,直向確認,九宮格確認即可
C++ code:
class Solution { public: int count[200]; int count1[200]; int square[10][10][200]; bool isValidSudoku(vector<vector<char>>& board) { for(int i=0;i<9;i++) { memset(count,0,sizeof(count)); memset(count1,0,sizeof(count)); for(int j=0;j<9;j++) { if(board[i][j]!='.') { if(count[board[i][j]]) return false; if(square[i/3][j/3][board[i][j]]) return false; square[i/3][j/3][board[i][j]]++; count[board[i][j]]++; } if(count1[board[j][i]]&&board[j][i]!='.') return false; count1[board[j][i]]++; } } return true; } };
沒有留言:
張貼留言