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

Appearance settings

Commit d860df9

Browse filesBrowse files
authored
Create 3 setMismatch.cpp
1 parent 2e2357e commit d860df9
Copy full SHA for d860df9

File tree

Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
vector<int> findErrorNums(vector<int>& nums) {
4+
5+
unordered_set <int> uset;
6+
vector<int> ans;
7+
for (int x: nums){
8+
if (uset.find(x) != uset.end()) {
9+
ans.push_back(x);
10+
}
11+
else {
12+
uset.insert(x);
13+
}
14+
}
15+
16+
int i;
17+
for(i = 1; i <= nums.size(); ++i){
18+
if (uset.find(i) == uset.end()){
19+
ans.push_back(i);
20+
}
21+
}
22+
23+
24+
return ans;
25+
}
26+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.