Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def tictactoe(self, moves: List[List[int]]) -> str:
- table = [[0] * 3 for _ in range(3)]
- i = 0
- while i < len(moves):
- x = moves[i][0]
- y = moves[i][1]
- if i % 2 == 0:
- table[x][y] = 7
- else:
- table[x][y] = 5
- i += 1
- print(table)
- for i in range(len(table)):
- if sum(table[i]) == 21:
- return "A"
- elif sum(table[i]) == 15:
- return "B"
- for j in range(3):
- s = 0
- for i in range(3):
- s = s + table[i][j]
- if s == 21:
- return "A"
- elif s == 15:
- return "B"
- i = 0
- j = 0
- s = 0
- while i < len(table) and j < len(table[0]):
- s += table[i][j]
- i += 1
- j += 1
- if s == 21:
- return "A"
- if s == 15:
- return "B"
- i = 0
- j = 2
- s = 0
- while i < 3 and j >= 0:
- s += table[i][j]
- i += 1
- j -= 1
- if s == 21:
- return "A"
- if s == 15:
- return "B"
- if len(moves) == 9:
- return "Draw"
- return "Pending"
Advertisement
Add Comment
Please, Sign In to add comment