[
two pointers
string
dp
]
BinarySearch 0287 Remove One Letter
Problem statement
https://binarysearch.com/problems/Remove-One-Letter/
Solution
Variation of Leetcode 0161 One Edit Distance, but here we have only once case.
Complexity
It is O(n)
for time and O(1)
for space.
Code
class Solution:
def solve(self, s, t):
n, m = len(s), len(t)
if n - m != 1:
return False
i1, i2 = 0, 0
while i1 < m and i2 < n:
if t[i1] == s[i2]:
i1, i2 = i1 + 1, i2 + 1
else:
i2 += 1
return i1 == m