There is an unordered array, P, consisting of integers that are less than 100,000.
Check whether there is a pair of values that can sum up to the given sum, k.
bool test(const vector<int>& arr, int k)
{
unordered_set<int> unord;
for (int value : arr)
{
if (unord.find(value) != unord.end())
{
return true;
}
unord.insert(k - value);
}
return false;
}
'Challenge' 카테고리의 다른 글
[LeetCode] Reverse Integer (0) | 2021.09.14 |
---|---|
[LeetCode] ZigZag Conversion (0) | 2021.09.13 |
[LeetCode] Longest Palindromic Substring (0) | 2021.09.12 |
[LeetCode] Median of Two Sorted Arrays (0) | 2021.09.11 |
[LeetCode] Longest Substring Without Repeating Characters (0) | 2021.09.11 |