32. One Edit Distance
Given two strings s0
and s1
determine whether they are one or zero edit distance away. An edit can be described as deleting a character, adding a character, or replacing a character with another character.
Constraints
n ≤ 100,000
wheren
is the length ofs0
.m ≤ 100,000
wherem
is the length ofs1
.
Example 1
Explanation
This has the edit distance of 0
, since they are the same string.
Example 2
Explanation
This has the edit distance 1
, since s
was added to the second string.
Example 3
Explanation
This has edit distance of 2
.
Solution: (Without DP)
Time Complexity: O(n)
Last updated