161. 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
s
to gett
. - Delete exactly one character from
s
to gett
. - Replace exactly one character of
s
with a different character to gett
.
Example 1:
1 | Input: s = "ab", t = "acb" |
Example 2:
1 | Input: s = "", t = "" |
Constraints:
0 <= s.length, t.length <= 10^4
s
andt
consist of lowercase letters, uppercase letters, and digits.
Hints/Notes
- 2025/02/19 Q2
- string
- Leetcode solution
Solution
Language: C++
1 | class Solution { |