class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
map<int, vector<int>> mp;
int n = nums.size();
for (int i = 0; i < n; i ++) {
mp[nums[i]].push_back(i);
}
for (int i = 0; i < n; i ++) {
int d = target - nums[i];
if(nums[i] != d && mp[d].size()) return {i, mp[d][0]};
if(nums[i] == d && mp[d].size() >= 2) {
if(i == mp[d][0]) return {i, mp[d][1]};
else return {i, mp[d][0]};
}
}
return {};
}
};