美文网首页
348. Design Tic-Tac-Toe

348. Design Tic-Tac-Toe

作者: 我是你的果果呀 | 来源:发表于2016-12-08 11:28 被阅读0次

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

相关文章

  • 348. Design Tic-Tac-Toe

    LeetCode Link size 为 n 的棋牌,player1 和 player2 轮流向空处置子,当 ro...

  • 348. Design Tic-Tac-Toe

    Design a Tic-tac-toe game that is played between two play...

  • 348. Design Tic-Tac-Toe

    Design a Tic-tac-toe game that is played between two play...

  • 348. Design Tic-Tac-Toe

    https://leetcode.com/problems/design-tic-tac-toe/discuss/...

  • Design Tic-Tac-Toe

    题目Design a Tic-tac-toe game that is played between two pl...

  • Ilya and tic-tac-toe game

    Ilya and tic-tac-toe game Ilya is an experienced player i...

  • Ilya and tic-tac-toe game

    Ilya is an experienced player in tic-tac-toe on the4 × 4f...

  • LeetCode 1275. Find Winner on a

    Tic-tac-toe is played by two players A and B on a 3 x 3 g...

  • 348.家风

    “王华到翰林院工作后,偶尔被调到冬宫给太子朱厚照讲课,太监刘瑾在那时和王华有旧。刘瑾还曾多次向王华请教一些知识,王...

  • 348. 秋实

    秋雨把绿叶的身姿卷在行人脚下,沾满泥水葱郁旺盛的绿色在一场秋雨一场寒中拜倒在秋天的石榴裙下 不管是秋雨,还是秋风扫...

网友评论

      本文标题:348. Design Tic-Tac-Toe

      本文链接:https://www.haomeiwen.com/subject/jxxsmttx.html