Given one is in ascending order Ordered array of , Find two numbers so that their sum equals the target number .

The function should return these two subscript values index1 and index2, among index1 Must be less than index2.

explain :

The returned subscript value (index1 and index2) It's not starting from scratch .
You can assume that each input corresponds to only one answer , And you can't reuse the same elements .
Examples :

input : numbers = [2, 7, 11, 15], target = 9
output : [1,2]
explain : 2 And 7 The sum is equal to the target number 9 . therefore index1 = 1, index2 = 2 .
class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) {
map<int,int> m; vector<int> result; for(int i=0;i<numbers.size();i++){ m[
numbers[i]]=i; } for(int i=0;i<numbers.size();i++){ const int gap = target-
numbers[i]; if(m.find(gap)!=m.end()&&m[gap]>i){ result.push_back(i+1); result.
push_back(m[gap]+1); break; } } return result; } };

Technology
©2019-2020 Toolsou All rights reserved,
In the problem of target detection “ recall Recall”,“ Accuracy Precision”Linux Page replacement algorithm C Language implementation About wechat payment body( Product description ) Problems encountered stay Vue Use in Web Worker Calculate the working days of each month c++ Memory Pointer out of bounds detection mechanism _CrtMemBlockHeadeJavaScript Medium Call and Apply Remember once EventBus Project issues caused by memory leaks Hundreds of millions of locusts rarely collide Locusts want to be self driving Heroes Java Swing JList: List box components