Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
不到英语四级的水平随便翻译一下,以后的不再详细说明
给一个integer 类型的数组,返回其中两个数的索引,这两个数的和等于target。
你可以认为每一个输入只有一个答案,所以你不能用其中的一个元素两次
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
我的思路很简单,不就是两两配对不重复嘛,就写了两个for循环,然后解决了问题,我的代码如下:
class Solution {
public int[] twoSum(int[] nums, int target) {
for(int i = 0 ;i<nums.length;i++){
for(int j = i+1;j<nums.length;j++){
if(num