File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
Python/chapter01/1.5 - OneAway Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -43,17 +43,16 @@ def one_away(s1: str, s2: str) -> bool:
43
43
s_short = s1 if len (s1 ) < len (s2 ) else s2
44
44
s_long = s1 if len (s1 ) > len (s2 ) else s2
45
45
46
- addend = 0
46
+ added = 0
47
47
for i , c in enumerate (s_short ):
48
- if c == s_long [i + addend ]:
48
+ if c == s_long [i + added ]:
49
49
continue
50
- if i == i + addend :
51
- # addend is 0, will check next char in next iteration
52
- addend += 1
53
- continue
54
- # otherwise, addend is not 0, and we did not match characters.
55
- # guaranteed at least 2 edit distance
56
- return False
50
+ # chars didn't match, will check next char in next iteration
51
+ added += 1
52
+ if added > 1 :
53
+ # added more than once, and we did not match characters.
54
+ # guaranteed at least 2 edit distance
55
+ return False
57
56
return True
58
57
59
58
You can’t perform that action at this time.
0 commit comments