【leetcode】1. Two Sum
在一个数组中找到和等于target的两个数的位置
按样例输入是乱序的,只能用n^2解法
public class Solution { public int[] twoSum(int[] nums, int target) { for (int i = 0; i < nums.length - 1; ++i) { int left = nums[i]; for (int j = i + 1; j < nums.length; ++j) { int right = nums[j]; if (left + right == target) { return new int[]{i, j}; } } } return null; } }