Question about time complexity, thanks

  • 0

    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){
    long l = (long) nums[i]-t;
    long r = (long) nums[i]+t;
    if(l <= r && !record.subSet(l,r+1).isEmpty()){
    return true;
    return false;
    I am quiet confused about the time complexity of this problem. Is there anyone explain it for me? Thanks a lot.

Log in to reply

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