Design a Tic-tac-toe game that is played between two players on anxngrid.
You may assume the following rules:
A move is guaranteed to be valid and is placed on an empty block.
Once a winning condition is reached, no more moves is allowed.
A player who succeeds in placingnof their marks in a horizontal, vertical, or diagonal row wins the game.
Follow up: Could you do better than O(n2) permove()operation?
初见这道题吓一跳, 发现好难, 遇到难题一定不要慌, 不能难到天上去, 任何问题都有解决的办法。
谁先将n*n 的矩阵 站上一条线谁先赢, 横竖对角线。 player1 的走的棋子value == 1, player2 走的棋子value == -1, 这样好计算是否成一条线,
在定义水平的数组, 垂直的数组, 两条对角线。 每move一次, 对应的位置加上value, 每次都检查是否有变量存满, 存满则返回当前player。 easy! 希望面试遇到这个题 , 看起来实现简单, 装逼100分。