Skip to content

Latest commit

 

History

History
18 lines (18 loc) · 487 Bytes

File metadata and controls

18 lines (18 loc) · 487 Bytes
class Solution {
    public int[] twoSum(int[] nums, int target) {
        //先找出其中一个数字
        for(int i=0;i<nums.length;i++){
            int second=target-nums[i];
            for(int j=i+1;j<nums.length;j++){
                if(nums[j]==second){
                   int[] answer= new int[]{i,j};
                    return answer;
                }
            }
        }
        return new int[]{-1,-1};
    }
}

https://leetcode-cn.com/problems/two-sum/