leetcode1275

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode1275相关的知识,希望对你有一定的参考价值。

 1 class Solution:
 2     def tictactoe(self, moves: List[List[int]]) -> str:
 3         n = len(moves)
 4         rowA = [0,0,0]
 5         rowB = [0,0,0]
 6         colA = [0,0,0]
 7         colB = [0,0,0]
 8         diaA,diaB,a_diaA,a_diaB =0,0,0,0
 9         for i in range(n):
10             x,y = moves[i][0],moves[i][1]
11             if i % 2 == 0:#turn A
12                 rowA[x] += 1
13                 colA[y] += 1
14                 if x == y:
15                     diaA += 1
16                 if x + y == 2:
17                     a_diaA += 1
18             else:#turn B
19                 rowB[x] += 1
20                 colB[y] += 1
21                 if x == y:
22                     diaB += 1
23                 if x + y == 2:
24                     a_diaB += 1
25         if diaA == 3 or a_diaA == 3:
26             return A
27         if diaB == 3 or a_diaB == 3:
28             return B
29         for j in range(3):
30             if rowA[j] == 3 or colA[j] == 3:
31                 return A
32             if rowB[j] == 3 or colB[j] == 3:
33                 return B
34         if n == 9:
35             return Draw
36         return Pending
37                 
38                 
39         

使用多个变量,存储行、列、对角线、反对角线等信息。

以上是关于leetcode1275的主要内容,如果未能解决你的问题,请参考以下文章

leetcode.1275找出井字棋的获胜者

leetcode1275. Find Winner on a Tic Tac Toe Game

LeetCode --- 1275. Find Winner on a Tic Tac Toe Game 解题报告

1275. 最大数

leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和](代码片段

codevs——1275 有鱼的声音