//c++classSolution{public:
vector<int>twoSum(vector<int>& numbers,int target){//key is the number and value is its index in the vector
unordered_map<int,int> hash;
vector<int> result;for(int i =0;i < numbers.size(); i++){int numberToFind = target - numbers[i];//if numberToFind is found in map, return themif(hash.find(numberToFind)!= hash.end()){//+1 because indices are NOT zero based
result.push_back(hash[numberToFind]);
result.push_back(i);return result;}//number was not found. Put it in the map.
hash[numbers[i]]= i;}return result;}};
//c++classSolution{public:
vector<int>twoSum(vector<int>& nums,int target){
unordered_map<int,int> map;int n =(int)nums.size();for(int i =0; i < n; i++){auto p = map.find(target - nums[i]);if(p != map.end()){return{p->second, i};}
map[nums[i]]= i;}return{0,0};}};
# pythonclassSolution:deftwoSum(self, nums: List[int], target:int):iflen(nums)<=1:returnFalse
buff_dict ={}for i inrange(len(nums)):if nums[i]in buff_dict:return[buff_dict[nums[i]], i]else:
buff_dict[target - nums[i]]= i
最喜欢的一个方法class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { //key is the number and value is its index in the vector unordered_map<i...