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,
C Review of basic language knowledge Go Language learning notes (GUI programming )Java Misunderstanding —— Method overloading is a manifestation of polymorphism ? How to achieve low cost and high stability for cloud native applications ?elementui Shuttle box el-transfer Display list content text too long C/C++ Memory model Element-Ui assembly Message Message prompt , alert Popup C# Making a simplified version of calculator Python In pycharm editor Interface style modification Tiktok refresh progress bar ( Two little balls turn ), The code is simple