基于要查找的次数来决定是否要预处理。预处理方式按照3进制来做。
另外,检查是否赢了要判断横行,纵列,正反对角线
package Moderate;
/**
* Design an algorithm to figure out if someone has won in a game of tic-tac-toe.
译文:
设计算法检查某人是否赢得了井字游戏。
*
*/
public class S17_2 {
// 方法一:如果HasWon函数需要被频繁调用
public static int convertBoardToInt(char[][] board) {
int factor = 1;
int sum = 0;
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
int v = 0;
switch(board[i][j]){
case 'x':
v = 1;
break;
case 'o':
v = 2;
break;
default:
v = 0;