Leetcode 348. Design Tic-Tac-Toe
来源:互联网 发布:久久网络 编辑:程序博客网 时间:2024/06/06 02:08
1、声明一个两个数组 rows, cols ,三个整数diagonal , anti_diagonal 和 size
2、用rows, cols,diagonal , anti_diagonal 来记录player 的 位置以便于检查获胜条件
public class TicTacToe { private int[] rows; private int[] cols; private int diagonal; private int anti_diagonal; private int size; public int move(int row, int col, int player) { int toAdd = player == 1 ? 1 : -1; rows[row] += toAdd; cols[col] += toAdd; if (row == col) diagonal += toAdd; if (col == (size - row - 1)) anti_diagonal += toAdd; return check(row,col,player); } private int check(int row, int col, int player) { if (Math.abs(rows[row]) == size || Math.abs(cols[col]) == size || Math.abs(diagonal) == size || Math.abs(anti_diagonal) == size ) {return player;} return 0; }}
0 0
- Leetcode Everyday: 348. Design Tic-Tac-Toe
- Leetcode 348. Design Tic-Tac-Toe
- leetcode Design Tic-Tac-Toe
- 348. Design Tic-Tac-Toe
- 348. Design Tic-Tac-Toe
- LeetCode 348. Design Tic-Tac-Toe(井字棋)
- [leetcode] 348. Design Tic-Tac-Toe 解题报告
- (未完成!)LeetCode 348. Design Tic-Tac-Toe 设计井字棋游戏
- [Leetcode] 348. Design Tic-Tac-Toe 解题报告
- Design Tic-Tac-Toe
- Design Tic-Tac-Toe
- Design Tic-Tac-Toe
- Tic-Tac-Toe
- [cf]Tic-tac-toe
- C - Tic-tac-toe
- Minimax-Tic Tac Toe
- FZU Tic-Tac-Toe
- Tic-Tac-Toe FZU
- Mysql并发时经典常见的死锁原因及解决方法
- MATLAB入门教程
- Discuz!开发之发帖回帖@会员功能代码解析
- View和ViewGroup
- 2017回顾优米网历年定位
- Leetcode 348. Design Tic-Tac-Toe
- ZOJ 1610 Count the Colors【线段树】
- DFS 奇偶剪枝 HDU 1010
- [扩展欧拉定理] BZOJ 4869 [Shoi2017]相逢是问候
- mysql5.7新特性探究
- Discuz!论坛运营之如何开启支持/反对或者顶/踩功能
- python2安装PIL等第三方库提示Python version 2.7 required, which was not found in the registry的解决方法
- 专门为哇哦好基友写的word如何自动生成目录
- 【CodeForces 797C】Minimal string(贪心+字符串)