这道题很简单,解法是双重循环+判断。注意不要把代码的双重循环变量搞错,我第一次提交的时候就踩到坑了。
话说第一题不是像其他OJ的A+B,是加深程度的A+B倒是很开心。
最喜欢special的东西了。
以下是我的代码:
class Solution {
public int[] twoSum(int[] nums, int target) {
for( int index = 0; index < nums.length;index++){
for(int indey = index + 1; indey < nums.length; indey++){
if( nums[index] + nums[indey] == target){
int a[] = new int[2];
a[0] = index;
a[1] = indey;
return a;
}
}
}
return null;
}
}