leecode220

1 class Solution:
2     def containsNearbyAlmostDuplicate(self, nums: List[int], k: int, t: int) -> bool:
3         if t == 0 and len(set(nums)) == len(nums):
4             return False
5         for i,v in enumerate(nums):
6             for j in range(i+1, min(i+k+1,len(nums))):
7                 if abs(nums[j]-nums[i])<=t:
8                     return True
9         return False

此题目差评如潮,懒得自己做了。

参考:https://leetcode.com/problems/contains-duplicate-iii/discuss/514029/Python-3-O(n2)

上一篇:python中找出某元素的索引值(enumerate、index函数)


下一篇:python3读取csv文件任意行列代码实例