сумма каких двух элементов вектора равна искомому числу

Вот код:

vector<int> twoSum(vector<int>& nums, int target) {
    unordered_map<int, pair<int, int>> hashMap;
    for (int i = 0; i < nums.size(); ++i)
        if (hashMap.find(nums[i]) == hashMap.end())
            hashMap[nums[i]] = { i, -1 };
        else
            hashMap[nums[i]] = { hashMap[nums[i]].first, i };
    for (auto it : hashMap) {
        int lF = target - it.first;
        if (hashMap.find(lF) != hashMap.end()) {
            if (it.second.second == -1) {
                return { it.second.first, hashMap.find(lF)->second.first };
            }
            else
                return { it.second.first, hashMap.find(lF)->second.second };
        }

    }
    return {};
}

Проблема в том, что на 59 тесте на литкоде функция дает неверное решение, а в IDE у меня возвращается верное решение -_-

nums = [2,4,11,3]
target = 6
Output
[3,3]
Expected
[0,1]

Что это? Какое-то Undefined Behaviour?


Ответы (0 шт):