day1:记LeetCode看到的正则和转置的骚操作

2020-08-15  本文已影响0人  airlineogur
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'
上一篇 下一篇

猜你喜欢

热点阅读