ptn = re.compile(r'(\w)\1{2,}')
class Solution:
@cache
def findMinStep(self, board: str, hand: str) -> int:
if not board: return 0
res = inf
for i, j in product(range(len(hand)), range(len(board) + 1)):
new_board, ct = board[:j] + hand[i] + board[j:], 1
while ct: new_board, ct = ptn.subn('', new_board)
if (r:=self.findMinStep(new_board, hand[:i] + hand[i+1:])) != -1: res = min(res, r + 1)
return res if res < inf else -1
祖玛游戏python
最新推荐文章于 2024-04-26 12:34:16 发布