0161. One Edit Distance
https://leetcode.com/problems/one-edit-distance
Description
Given two strings s and t, return true if they are both one edit distance apart, otherwise return false.
A string s is said to be one distance apart from a string t if you can:
Insert exactly one character into
sto gett.Delete exactly one character from
sto gett.Replace exactly one character of
swith a different character to gett.
Example 1:
**Input:** s = "ab", t = "acb"
**Output:** true
**Explanation:** We can insert 'c' into s to get t.Example 2:
**Input:** s = "", t = ""
**Output:** false
**Explanation:** We cannot get t from s by only one step.Example 3:
**Input:** s = "a", t = ""
**Output:** trueExample 4:
Constraints:
0 <= s.length <= 1040 <= t.length <= 104sandtconsist of lower-case letters, upper-case letters and/or digits.
ac1: iterative
ac2: compare substring
Last updated
Was this helpful?