1. Two Sum
问题:给定数组中找到两个数之和等于特定值。
自己写的:(java)
public class Solution {
public int[] twoSum(int[] nums, int target) {
int resultTag = 0;
int i=0,j=0;
outterLoop:for (i = 0; i < nums.length; i++) {
for (j = i+1; j < nums.length; j++) {
//System.out.println(nums[j]);
if (nums[i] + nums[j] == target) {
resultTag = 1;
break outterLoop;
}
}
}
if (resultTag == 1) {
int[] result = new int[]{i,j};
return result;
}
else {
return null;
}
}
}