Description
LINK: https://leetcode.com/problems/two-sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
1 | Given nums = [2, 7, 11, 15], target = 9, |
Solution
1 | static auto x = [](){ |
Discussion
前面那一段,用来解决频繁输出到stdout中很费时间的问题。
后面,用unordered_map实现快速查找,很神奇。
另外,把unordered_map<int, int> umap;的初始化放到函数外面,进一步提速(很trick)。