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, and you may not use the same element twice.
//暴力解法
class Solution {
public int[] twoSum(int[] nums, int target) {
int[] result = new int[2];
int len = nums.length;
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
if (i != j && target == nums[i] + nums[j]) {
result[0] = i;
result[1] = j;
return result;
}
}
}
return result;
}
}