leetcode第321题 LeetCode解题
leetcode第321题解题争取每天做一题LeetCode上的题,坚持就是胜利!题目:给定一个数组和一个目标数值,求数组内两数相加之和等于目标数值的下标。假定必有一组解。示例:Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]。解题思路如下:遍历数组,判断是否有nums[j] = target - nums[i]。public int[] tw< nums. ; i++) { for (int j = i + 1; j < nums. ; j++) { (nums[j] == target - nums[i]) { new int[]{i, j}; } } } throw new IllegalArgumentExcepti"No two sum solution"); }
int[] nums, int target) { for (int i = 0; i