Online judge for leetcode

Question 1: Two Sum

 1 class Solution {
 2 public:
 3     vector<int> twoSum(vector<int> &numbers, int target) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         vector<int> res;
 7         vector<int>::size_type index1, index2;
 8         
 9         for (index1 = 0; index1 < numbers.size() - 1; index1++) {
10             for (index2 = index1 + 1; index2 < numbers.size(); index2++) {
11                 if (numbers[index1] + numbers[index2] == target) {
12                     res.push_back(index1 + 1);
13                     res.push_back(index2 + 1);
14                     return res;
15                 }
16             }
17         }
18     }
19 };
原文地址:https://www.cnblogs.com/sunj/p/3304417.html