标签:
按样例输入是乱序的,只能用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; } }
标签:
原文地址:http://www.cnblogs.com/lanhj/p/5373173.html