从数组中找两元素,其和等于给定的数

最直观的方法是两次扫描数组,判断target-array[i]是否存在数组中。这样作的时间复杂度是O(n^2)。数组 如何保存以前的处理结果?可使用hash table "target - array[i]是否存在数组中。code vector<int> addsToTarget(vector<int>& numbers,int target) { unordered_map<int,in
相关文章
相关标签/搜索