160. One Edit Distance
# Medium
题意:两个字符串s
和t
,要让s执行一次变换变成t
返回True,否则False,只有三种形式的变换:
insert one char into
s
to gett
, eg. "ab" -> "acb"delete one char from
s
to gett
, eg. "abc" -> "ab"replace one char of
s
to gett
, eg. "1203" -> "1213"
Solutions:
if length difference is bigger than 1, return False
if length difference is equal to 1, then only allow one char different, longer string moves to next char
if length difference is 0, then only allow one char different, both strings move to next char
Last updated
Was this helpful?