美文网首页
day1:记LeetCode看到的正则和转置的骚操作

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

作者: airlineogur | 来源:发表于2020-08-15 19:35 被阅读0次
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