1275. 找出井字棋的获胜者
int[][] pad = new int[3][3];
for(int i = 0; i < moves.length; i++) {
int r = moves[i][0], c = moves[i][1];
if(i % 2 == 0) {
pad[r][c] = 1;
}else {
pad[r][c] = 2;
}
if(i >= 4 && judge(pad) != 3) {返回三个值
return judge(pad) == 1 ? "A" : "B";
}
}
return moves.length == 9 ? "Draw" : "Pending";
}
public int judge(int[][] pad) {
for(int i = 0; i < 3; i++) {
if(pad[i][0] == pad[i][1] && pad[i][1] == pad[i][2] && pad[i][0] != 0) {行
return pad[i][0] == 1 ? 1 : 2;
}
else if(pad[0][i] == pad[1][i] && pad[1][i] == pad[2][i] && pad[0][i] != 0) {列
return pad[0][i] == 1 ? 1 : 2;
}
}
if(pad[0][0] == pad[1][1] && pad[1][1] == pad[2][2] && pad[0][0] != 0) {主对角线
return pad[0][0] == 1 ? 1 : 2;
}
else if(pad[0][2] == pad[1][1] && pad[1][1] == pad[2][0] && pad[2][0] != 0) {副对角线
return pad[2][0] == 1 ? 1 : 2;
}
return 3;证明没有连成行的
}
1260. 二维网格迁移
int r = grid.length, c = grid[0].length;
int[] pre = new int[r * c];
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
k %= pre.length;k一直在增加
pre[k++] = grid[i][j];
}
}
k = 0;k直接赋0
List<List
for(int i = 0; i < r; i++) {
List
for(int j = 0; j < c; j++) {
path.add(pre[k++]);这里直接用k
}
ans.add(path);
}