给定 nums = [2, 7, 11, 15], target = 9
因为 nums[0] + nums[1] = 2 + 7 = 9
所以返回 [0, 1]
/**
* 给定 nums = [2, 7, 11, 15], target = 9
* <p>
* 因为 nums[0] + nums[1] = 2 + 7 = 9
* 所以返回 [0, 1]
* <p>
* 来源:力扣(LeetCode)
* 链接:https://leetcode-cn.com/problems/two-sum
* 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
*/
public static ArrayList<int[]> getCount(int[] arrs, int count) throws IllegalAccessException {
ArrayList<int[]> arrayList = new ArrayList<>();
if (arrs.length > 0) {
for (int i = 0; i < arrs.length; i++) {
for (int j = i + 1; j < arrs.length; j++) {
while (arrs[j] == count - arrs[i]) {
arrayList.add(new int[]{i,j});
break;
}
}
}
return arrayList;
}
throw new IllegalAccessException("No two sum solution");
}