目录
牛客_井字棋
解析代码
牛客_井字棋
井字棋__牛客网
解析代码
class Board {public:bool checkWon(vector<vector<int> > board) {// 当前玩家是否胜出!!!不是有玩家胜出int row = board.size(), col = board[0].size();for (int i = 0, cnt = 0; i < row; ++i) { // 每行for (int j = 0; j < col; ++j)cnt += board[i][j];// if (cnt == col || cnt == -col)// 当前玩家是否胜出!!!不是有玩家胜出if (cnt == col)return true;}for (int i = 0, cnt = 0; i < col; ++i) { // 每列for (int j = 0; j < row; ++j)cnt += board[i][j];// if (cnt == row || cnt == -row)// 当前玩家是否胜出!!!不是有玩家胜出if (cnt == row)return true;}int cnt = 0;for (int i = 0; i < row; ++i) {cnt += board[i][i];}// if (cnt == row || cnt == -row)// 当前玩家是否胜出!!!不是有玩家胜出if (cnt == row)return true;cnt = 0;for (int i = 0; i < row; ++i) {cnt += board[i][row - 1 - i];}// if (cnt == row || cnt == -row)// 当前玩家是否胜出!!!不是有玩家胜出if (cnt == row)return true;return false;}
};