day1:记LeetCode看到的正则和转置的骚操作
import re
from itertools import chain
class Solution:
def tictactoe(self, board: List[str]) -> str:
N = len(board)
pattern = re.compile(r'^([XO])\1*$')
for line in chain(board, map(''.join, zip(*board)), (''.join(board[i][i] for i in range(N)),), (''.join(board[N-1-i][i] for i in range(N)),)):
match_obj = pattern.match(line)
if match_obj:
return match_obj.group(1)
if ' ' in chain.from_iterable(board):
return "Pending"
return 'Draw'
本文标题:day1:记LeetCode看到的正则和转置的骚操作
本文链接:https://www.haomeiwen.com/subject/xsaadktx.html
网友评论