一:两数之和
题目要求:
解题思路:
常规思路(暴力方法):定义两个指针遍历,满足条件时,返回下标。
优化版本:如下图
实现代码:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> ret;
unordered_map<int,int> hash;
for(int i = 0; i < nums.size(); i++) {
int tmp = target - nums[i];
if(hash.count(tmp)) {
return {hash[tm