Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f35ccf

Browse files
raof01azl397985856
authored andcommitted
feat : add c++ code 219.contains-duplicate-ii.md (azl397985856#129)
1 parent d51a928 commit 6f35ccf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

‎problems/219.contains-duplicate-ii.md‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Output: false
3636

3737
## 代码
3838

39-
* 语言支持:JS,Python
39+
* 语言支持:JS,Python,C++
4040

4141
Javascript Code:
4242

@@ -116,3 +116,22 @@ class Solution:
116116
d[num] = index
117117
return False
118118
```
119+
C++ Code:
120+
```C++
121+
class Solution {
122+
public:
123+
bool containsNearbyDuplicate(vector<int>& nums, int k) {
124+
auto m = unordered_map<int, int>();
125+
for (int i = 0; i < nums.size(); ++i) {
126+
auto iter = m.find(nums[i]);
127+
if (iter != m.end()) {
128+
if (i - m[nums[i]] <= k) {
129+
return true;
130+
}
131+
}
132+
m[nums[i]] = i;
133+
}
134+
return false;
135+
}
136+
};
137+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /