
package com.lsy.leetcodehot100;public class _Hot1_两数之和 {public static int[] twoSum1(int[] nums, int target) {int[] arr = new int[2];for (int i = 0; i < nums.length; i++) {for (int j = 1; j < nums.length; j++) {if (nums[i] + nums[j] == target) {arr[0] = i;arr[1] = j;return arr;}}}return null;}public static int[] twoSum2(int[] nums, int target) {for (int i = 0; i < nums.length; i++) {int temp = target - nums[i];for (int j = 0; j < nums.length; j++) {if (i == j) {continue;}if(temp == nums[j]){return new int[]{i,j};}}}return null;}public static void main(String[] args) {int[] arr = {2, 6, 5, 8, 12, 7, 11, 9};int[] result = twoSum1(arr, 14);for (int item : result) {System.out.println(item);}}
}