傻逼题目是真的傻逼,还非要说“但这里的规则稍有不同”,不同你个嘚不同;
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param board char字符型vector<vector<>>
* @return bool布尔型
*/
bool isValidTwilightSudoku(vector<vector<char> >& board) {
// write code here
// 不用求解,只需验证是否有效即可
// 利用三个哈希表,分别验证 行、列、宫
map<int,set<int>> m_row, m_col, m;
int row = board.size();
int col = board[0].size();
for(int i=0; i<row; ++i)
{
for(int j=0; j<col; ++j)
{
if(board[i][j]!='.')
{
if(m_row[i].count(board[i][j]))
return false;
if(m_col[j].count(board[i][j]))
return false;
int t = i/3*2+j/3;
if(m[t].count(board[i][j]))
return false;
// 判断稍有不同的那些规则
// 注意t从0开始
// if(((t==0||t==4||t==8) && (board[i][j]!=1&&board[i][j]!=2&&board[i][j]!=3)) || ((t==1||t==5) && (board[i][j]!=4&&board[i][j]!=5&&board[i][j]!=6)) || ((t==2||t==6) && (board[i][j]!=7&&board[i][j]!=8&&board[i][j]!=9)))
// {
// cout << "t = " << t << " board[i][j] = " << board[i][j] << endl;
// return false;
// }
m_row[i].emplace(board[i][j]);
m_col[j].emplace(board[i][j]);
m[t].emplace(board[i][j]);
}
}
}
return true;
}
};