题目:
class Board {
public:
bool checkWon(vector<vector<int> > board) {
// write code here
int rows = board.size();
int cols = board[0].size();
// 行
for(int i = 0; i<rows; i++)
{
int sum = 0;
for(int j = 0; j<cols; j++)
{
sum += board[i][j];
}
if(sum == 3)
return true;
}
// 列
for(int i = 0; i<cols; i++)
{
int sum = 0;
for(int j = 0; j<rows; j++)
{
sum += board[i][j];
}
if(sum == 3)
return true;
}
// 对角
if(board[0][0] + board[1][1] + board[2][2] == 3 || board[0][2] + board[1][1] + board[2][0] == 3)
return true;
return false;
}
};