One Edit Distance

Given two stringss andt, determine if they are both one edit distance apart.

Note:

There are 3 possiblities to satisfy one edit distance apart:

  1. Insert a character into s to get t

  2. Delete a character from s _to get t_

  3. Replace a character of s to get t

Example

Example 1:

Input:
s = "ab", 
t = "acb"

Output: true

Explanation:
 We can insert 'c' into s
 to get t.

Example 2:

Example 3:

Note

当当前位置不一样的时候,根据三种情况分别比较substring

edge case 长度差一,最后多一位,最后判断一下

Code

Last updated