1.算法描述
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
2.要求运行结果eg:
输入:nums = [3,2,4], target = 6 输出:[1,2]
3.java demo实现
1).for循环实现
public int[] twoSum(int[] nums, int target) {
int[] sumArray=new int[2];
for(int i=0;i
2).hashmap实现
public int[] twoSum(int[] nums, int target) {
int[] sumArray=new int[2];
HashMap tempNum=new HashMap<>();
tempNum.put(nums[0],0);
for(int i=0;i



