Skip to content

Commit ffcb1b3

Browse files
committed
Dec 5
1 parent 779249e commit ffcb1b3

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Solution:
2+
def canChange(self, start: str, target: str) -> bool:
3+
n = len(start)
4+
ptr1, ptr2 = 0, 0
5+
6+
while ptr1 < n or ptr2 < n:
7+
while ptr1 < n and start[ptr1] == '_':
8+
ptr1 += 1
9+
while ptr2 < n and target[ptr2] == '_':
10+
ptr2 += 1
11+
if n == ptr1 or n == ptr2:
12+
return ptr1 == ptr2 == n
13+
if start[ptr1] != target[ptr2]:
14+
return False
15+
if start[ptr1] == 'L':
16+
if ptr1 < ptr2:
17+
return False
18+
else:
19+
if ptr1 > ptr2:
20+
return False
21+
ptr1 += 1
22+
ptr2 += 1
23+
24+
return True
25+
26+
27+
def main():
28+
start = '_L__R__R_'
29+
target = '_L__R__R_'
30+
assert Solution().canChange(start, target) is True
31+
32+
start = 'R_L_'
33+
target = '__LR'
34+
assert Solution().canChange(start, target) is False
35+
36+
start = '_R'
37+
target = 'R_'
38+
assert Solution().canChange(start, target) is False
39+
40+
41+
if __name__ == '__main__':
42+
main()

2024-12-December-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| December 2 | [1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | Solved |
88
| December 3 | [2109. Adding Spaces to a String](https://leetcode.com/problems/adding-spaces-to-a-string/) | Medium | Solved |
99
| December 4 | [2825. Make String a Subsequence Using Cyclic Increments](https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/) | Medium | Solved |
10-
| December 5 | []() | | |
10+
| December 5 | [2337. Move Pieces to Obtain a String](https://leetcode.com/problems/move-pieces-to-obtain-a-string/) | Medium | Unsolved |
1111
| December 6 | []() | | |
1212
| December 7 | []() | | |
1313
| December 8 | []() | | |
@@ -39,5 +39,5 @@
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
4141
| Easy | 2 | 2 | 0 |
42-
| Medium | 2 | 2 | 0 |
42+
| Medium | 3 | 2 | 1 |
4343
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)