Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
558 B
1
Indexable
Never
bool containsNearbyDuplicate(vector<int>& nums, int k) {
        if(nums.size() == 0) return false;
        if(nums.size() == 1) return false;
        if(k > nums.size()){
            k = nums.size();
        }
        
        for(int i = 0; i+k < nums.size(); i++){
            
            for(int j = i+1; j <= i+k ; j++){
             if(j < nums.size()){
                    if(nums[i] == nums[j]){
                    return true;
                }
             }   
             
            }
        }
        return false;
    }