花点时间Debug,还是捣鼓出来了,效果还行~~~
My own code:
class Solution(object):
def containsNearbyAlmostDuplicate(self, nums, k, t):
"""
:type nums: List[int]
:type k: int
:type t: int
:rtype: bool
"""
if k==0:
return False
if t==0:
if len(set(nums))!=len(nums):
return True
else:
return False
le=len(nums)
for i in range(le):
a=max(i-k,0)
b=min(i+k,le-1)
for j in range(a,b):
if abs(nums[i]-nums[j])<=t and j!=i:
return True
return False