半監督- Distance-wise Graph Contrastive Learning
阿新 • • 發佈:2021-12-20
給你一個整數陣列 nums 和兩個整數k 和 t 。請你判斷是否存在 兩個不同下標 i 和 j,使得abs(nums[i] - nums[j]) <= t ,同時又滿足 abs(i - j) <= k 。
如果存在則返回 true,不存在返回 false。
來源:力扣(LeetCode)
連結:https://leetcode-cn.com/problems/contains-duplicate-iii
著作權歸領釦網路所有。商業轉載請聯絡官方授權,非商業轉載請註明出處。
滑動視窗 + 有序表
心之所向,素履以往 生如逆旅,一葦以航class Solution { public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) { int n = nums.length; TreeSet<Long> set = new TreeSet<Long>(); for (int i = 0; i < n; i++) { Long ceiling = set.ceiling((long) nums[i] - (long) t); if (ceiling != null && ceiling <= (long) nums[i] + (long) t) { return true; } set.add((long) nums[i]); if (i >= k) { set.remove((long) nums[i - k]); } } return false; } }