解题思路:
(1)设置行数组和列数组,以及记录正反对角的两个值
(2)依次判断每次落子之后,该行或者该列,或者正反对角是否出现三个同样的棋子
class Solution {
public:
string tictactoe(vector<vector<int>>& moves) {
//设置行数组,列数组,正反对角
int *row = new int[3]();
int *col = new int[3]();
int diag = 0,oiag = 0;
for(int i=0;i<moves.size();i++) {
int x = moves[i][0];
int y = moves[i][1];
if(i%2==0) {
row[x]++;
col[y]++;
if(x==y) diag++;
if(x==2-y) oiag++;
} else {
row[x]--;
col[y]--;
if(x==y) diag--;
if(x==2-y) oiag--;
}
if(row[x]==3 || col[y]==3 || diag==3 || oiag==3) return "A";
if(row[x]==-3 || col[y]==-3 || diag==-3 || oiag==-3) return "B";
}
if(moves.size()<9) return "Pending";
return "Draw";
}
};