Skip to content

Commit

Permalink
Merge pull request #9 from sumit-kushwah/main
Browse files Browse the repository at this point in the history
solved set mis match problem
  • Loading branch information
17mi540 authored Oct 23, 2022
2 parents 0911d0a + 61aee03 commit 411e2da
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions solutions/set_mismatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// problem link:

#include<bits/stdc++.h>
#include<unordered_map>

using namespace std;

class Solution {
public:
// write your code here

vector<int> findErrorNums(vector<int>& nums) {
sort(nums.begin(), nums.end());
vector<int> ans;
for (int i = 1; i < nums.size(); i++) {
if (nums[i] == nums[i - 1]) {
ans.push_back(nums[i]);
}
}
vector<int> m(nums.size());
for (int i = 0; i < nums.size(); i++) {
m[nums[i] - 1] = 1;
}
for(int i = 0; i < nums.size(); i++) {
if (m[nums[i] - 1] == 0) {
ans.push_back(i + 1);
}
}
return ans;
}

};

int main() {
Solution s;

}

0 comments on commit 411e2da

Please sign in to comment.