<s> """<STR_LIT>""" <EOL> from collections import OrderedDict <EOL> __author__ = '<STR_LIT>' <EOL> class Solution : <EOL> def containsNearbyAlmostDuplicate ( self , nums , k , t ) : <EOL> """<STR_LIT>""" <EOL> if k < <NUM_LIT:1> or t < <NUM_LIT:0> : <EOL> return False <EOL> if t == <NUM_LIT:0> : <EOL> return self . containsNearByDuplicate ( nums , k ) <EOL> od = OrderedDict ( ) <EOL> for n in nums : <EOL> key = n / t <EOL> for j in ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) : <EOL> m = od . get ( key + j ) <EOL> if m is not None and abs ( m - n ) <= t : <EOL> return True <EOL> while len ( od ) >= k : <EOL> od . popitem ( False ) <EOL> od [ key ] = n <EOL> return False <EOL> def containsNearByDuplicate ( self , nums , k ) : <EOL> od = OrderedDict ( ) <EOL> for n in nums : <EOL> if od . get ( n ) : <EOL> return True <EOL> while len ( od ) >= k : <EOL> od . popitem ( False ) <EOL> od [ n ] = n <EOL> return False <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print Solution ( ) . containsNearbyAlmostDuplicate ( [ - <NUM_LIT:3> , <NUM_LIT:3> ] , <NUM_LIT:2> , <NUM_LIT:4> ) </s>
