-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path777.py
51 lines (45 loc) · 1.67 KB
/
777.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def canTransform(self, s: str, t: str) -> bool:
if not s or not t:
return not s and not t
if len(s) != len(t):
return False
n = len(s)
i = j = 0
while i < n or j < n:
while i < n and s[i] == 'X':
i += 1
while j < n and t[j] == 'X':
j += 1
if i >= n or j >= n:
return i >= n and j >= n
if s[i] != t[j]: return False
if s[i] == 'L' and i < j: return False
if s[i] == 'R' and i > j: return False
i += 1
j += 1
return i >= n and j >= n
__________________________________________________________________________________________________
sample 13172 kb submission
class Solution:
def canTransform(self, start: str, end: str) -> bool:
if start.replace('X', '') != end.replace('X', ''):
return False
t = 0
for i in range(0, len(start)):
if start[i] == 'L':
while t < len(end) and end[t] != 'L':
t += 1
if i < t:return False
t += 1
t = 0
for i in range(0, len(start)):
if start[i] == 'R':
while t < len(end) and end[t] != 'R':
t += 1
if i > t:return False
t += 1
return True
__________________________________________________________________________________________________