public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
        if (nums == null) return false;
        TreeSet<Long> tree = new TreeSet<Long>();
        for (int i = 0; i < nums.length; ++i) {
            long n = nums[i];
            if ((tree.floor(n) != null && n - tree.floor(n) <= t) ||
                (tree.ceiling(n) != null && tree.ceiling(n) - n <= t)) return true;
            tree.add(n);
            if (i >= k) tree.remove((long)nums[i - k]);
        }
        return false;
    }