348. Design Tic-Tac-Toe

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分。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容