Re: [Easy AC solution using TreeSet<Long>](in Java)

public class Solution {

public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {

SortedSet<Long> record = new TreeSet<>();

for(int i = 0; i < nums.length; i++){

if(i > k){

record.remove((long)nums[i-k-1]);

}

long l = (long) nums[i]-t;

long r = (long) nums[i]+t;

if(l <= r && !record.subSet(l,r+1).isEmpty()){

return true;

}

record.add((long)nums[i]);

}

return false;

}

}

I am quiet confused about the time complexity of this problem. Is there anyone explain it for me? Thanks a lot.