1

给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。

class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] a = new int[2];
        int length = nums.length;
        for(int i = 0; i < length-1 ;i++){
            for (int j = i + 1;j < length; j++){
                if (nums[i] + nums[j] == target){
                    a[0] = i;
                    a[1] = j;
                    break;
                }
                else
                    continue;
            }
        }
        return a;
    }
}

 

posted @ 2018-07-09 18:25  Qian_Lu  阅读(71)  评论(0)    收藏  举报