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?
初見(jiàn)這道題嚇一跳, 發(fā)現(xiàn)好難, 遇到難題一定不要慌, 不能難到天上去, 任何問(wèn)題都有解決的辦法义黎。
誰(shuí)先將n*n 的矩陣 站上一條線誰(shuí)先贏, 橫豎對(duì)角線。 player1 的走的棋子value == 1歪赢, player2 走的棋子value == -1, 這樣好計(jì)算是否成一條線单料,?
在定義水平的數(shù)組埋凯, 垂直的數(shù)組点楼, 兩條對(duì)角線。 每move一次白对, 對(duì)應(yīng)的位置加上value掠廓, 每次都檢查是否有變量存滿, 存滿則返回當(dāng)前player甩恼。 easy蟀瞧! 希望面試遇到這個(gè)題 , 看起來(lái)實(shí)現(xiàn)簡(jiǎn)單条摸, 裝逼100分悦污。