{"rsdb":{"rid":"314444","subhead":"","postdate":"0","aid":"227631","fid":"49","uid":"1","topic":"1","content":"
\n

Two Sum<\/a><\/h2> \n
Given an array of integers, return indices of the two numbers such that they add up to a specific target.\n\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.<\/code><\/pre> \n 

Example:<\/h3> \n
Given nums = [2, 7, 11, 15], target = 9,\n\nBecause nums[0] + nums[1] = 2 + 7 = 9,\nreturn [0, 1].<\/code><\/pre> \n 

Code<\/h3> \n
\/\/\n\/\/  main.cpp\n\/\/  STL_Vector\n\/\/\n\/\/  Created by mac on 2019\/7\/13.\n\/\/  Copyright © 2019 mac. All rights reserved.\n\/\/\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\n\n\nusing namespace std;\n\nclass Solution{\npublic:\n    vector<int> twoSum(vector<int>& nums,int target){\n        vector<int> result;\n        for (int i=0; i<nums.size()-1; i++) {\n            for (int j=i+1; j<nums.size(); j++) {\n                if (nums[i]!=nums[j]) {\n                    if (nums[i]+nums[j]==target) {\n                        result.push_back(i);\n                        result.push_back(j);\n                    }\n                }\n            }\n        }\n        return result;\n    }\n};\n\nint main(int argc, const char * argv[]) {\n    \/\/ insert code here...\n    Solution solu;\n    vector<int> nums={2, 7, 11, 15};\n    \/\/int nums [4]= {2, 7, 11, 15};\n    int target=9;\n    \n    \n    for (int i=0; i<solu.twoSum(nums, target).size();i++) {\n        cout<<solu.twoSum(nums, target)[i]<<endl;\n    }\n    return 0;\n}\n<\/code><\/pre> \n 

\u8fd0\u884c\u7ed3\u679c<\/h3> \n
0\n1\nProgram ended with exit code: 0<\/code><\/pre> \n 

\u53c2\u8003\u6587\u732e<\/h3> \n