解题思路:
根据题目要求, 当前玩家想要获胜的话, 必须在横竖斜方向有连成排的即获胜
根据测试样例可知, 连成排的那一排和为3
那么当某一排的和为3
时则输出true
import java.util.*;
public class Board {
public boolean checkWon(int[][] board) {
boolean b = false;
if(board[0][0] + board[1][1] + board[2][2] == 3
|| board[0][2] + board[1][1] +board[2][0] == 3){
b = true;
}
for(int i = 0; i < 3; i++){
if(board[i][0] + board[i][1] + board[i][2] == 3
|| board[0][i] + board[1][i] + board[2][i] == 3){
b = true;
}
}
return b;
}
}