BST java solution

  • -2
    public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
            if(nums==null || nums.length < 2) return false;
            BinarySearchTree bst = new BinarySearchTree();
            for(int i =0;i<nums.length;i++){
                if(i>=k+1) bst.remove(nums[i-k-1]);
                long cur = nums[i];
                long low = Math.max(cur-t,Integer.MIN_VALUE);
                long high = Math.min(cur+t,Integer.MAX_VALUE);
                if(bst.has((int)low,(int)high)) return true;
            return false;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.