Skip to content

Commit 38ed736

Browse files
committed
cpp
1 parent f124f7e commit 38ed736

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public:
3+
bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {
4+
int n=nums.size();
5+
vector<pair<int,int>>mp;
6+
for(int i=0;i<n;i++){
7+
mp.push_back(make_pair(nums[i],i));
8+
}
9+
int start=0;
10+
int end=1;
11+
sort(mp.begin(),mp.end());
12+
while(end<n){
13+
long long int d1=mp[start].first;
14+
long long int d2=mp[end].first;
15+
if( abs(mp[start].second - mp[end].second) <=k && abs(d1-d2) <=t ){
16+
return 1;
17+
}
18+
if(abs(mp[start].second - mp[end].second) >k){
19+
end++;
20+
}
21+
if(abs(d1-d2) >t){
22+
start++;
23+
}
24+
if(start==end){
25+
end++;
26+
}
27+
}
28+
return 0;
29+
}
30+
};

0 commit comments

Comments
 (0)