<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class Solution ( object ) : <EOL> def isOneEditDistance ( self , s , t ) : <EOL> """<STR_LIT>""" <EOL> m , n = len ( s ) , len ( t ) <EOL> if m > n : return self . isOneEditDistance ( t , s ) <EOL> if n - m > <NUM_LIT:1> : return False <EOL> diff = <NUM_LIT:0> <EOL> i , j = <NUM_LIT:0> , <NUM_LIT:0> <EOL> while i < m and j < n and diff < <NUM_LIT:2> : <EOL> if s [ i ] == t [ j ] : <EOL> i += <NUM_LIT:1> <EOL> j += <NUM_LIT:1> <EOL> else : <EOL> if m != n : <EOL> j += <NUM_LIT:1> <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> j += <NUM_LIT:1> <EOL> diff += <NUM_LIT:1> <EOL> return diff == <NUM_LIT:1> or diff == <NUM_LIT:0> and m != n <EOL> class Solution1 ( object ) : <EOL> def isOneEditDistance ( self , s , t ) : <EOL> """<STR_LIT>""" <EOL> m , n = len ( s ) , len ( t ) <EOL> if m > n : return self . isOneEditDistance ( t , s ) <EOL> if n - m > <NUM_LIT:1> : return False <EOL> diff = <NUM_LIT:0> <EOL> i , j = iter ( s ) , iter ( t ) <EOL> a , b = next ( i , None ) , next ( j , None ) <EOL> while a and b and diff < <NUM_LIT:2> : <EOL> if a == b : <EOL> a , b = next ( i , None ) , next ( j , None ) <EOL> else : <EOL> if m != n : <EOL> b = next ( j , None ) <EOL> else : <EOL> a , b = next ( i , None ) , next ( j , None ) <EOL> diff += <NUM_LIT:1> <EOL> return diff == <NUM_LIT:1> or diff == <NUM_LIT:0> and m != n </s>
