题意:给定一个数组和一个目标值,输出数组中值之和等于目标值的两个元素的索引值
解法一:暴力(也是自己的解法),两重循环暴搜
class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> ans; for (int i = 0; i < nums.size(); i++) { for (int j = i+1; j < nums.size(); j++) { if (nums[i]+nums[j] == target) { ans.push_back(i); ans.push_back(j); } } } return ans; } };