标签:
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution.
class Solution { public: vector<int> twoSum(vector<int> &numbers, int target) { vector<int>res; for(int i=0;i<numbers.size();i++){ int n=target-numbers[i]; for(int j=0;j<numbers.size();j++) if(j!=i&&numbers[j]==n){ if(i>j){ int temp=j; j=i; i=temp; } res.push_back(i); res.push_back(j); return res; } } } };
标签:
原文地址:http://www.cnblogs.com/wqkant/p/5280821.html