Move Pieces to Obtain a String LeetCode solution in Python

1
class Solution:
2
def canChange(self, A: str, B: str) -> bool:
3
P = lambda c: c != "_"
4
I = lambda s, x: [i for i, c in enumerate(s) if c == x]
5
G = lambda d, p: all(p(x, y) for x, y in zip(I(A, d), I(B, d)))
6
S = lambda: [*filter(P, A)] == [*filter(P, B)]
7
return S() and G("L", ge) and G("R", le)
8

9

10
# 1. 2. 3.

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0