Created
January 9, 2018 14:49
-
-
Save s4553711/4224f39d95c46302c184700c2a94b165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) { | |
map<long, int> m; | |
int j = 0; | |
for(int i = 0; i < nums.size(); i++) { | |
if (i - j > k && m[nums[j]] == j) m.erase(nums[j++]); | |
auto a = m.lower_bound((long)nums[i] - t); | |
if (a != m.end() && abs(a->first - nums[i]) <= t) return true; | |
m[nums[i]] = i; | |
} | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment