class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> hash;
vector<int> result;
for (int i = 0; i < nums.size(); ++i)
{
int numToFind = target - nums[i];
if (hash.find(numToFind) != hash.end())
{
result.push_back(hash[numToFind]);
result.push_back(i);
return result;
}
else
{
hash[nums[i]] = i;
}
}
return result;
}
};
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
in worst_case unordered_map insertion takes O(n^2) time
and also you are using find function in worst _case it will take O(n) time it is O(n^2) solution then.
referece: geeksforgeeks.org/how-to-use-unord....