public void twoPoint(int[] nums,int target){
    int low=0,high=nums.length-1;
    while (low<high){
       int sum=nums[low]+nums[high];
        if(sum==target){
            System.out.println(low+","+high);
        }else if(sum < target){
            low++;
        }else{
            high--;
        }
    }
}

 

public void twoSum(){
    int [] nums={1,2,6,5};
    int target=6;
    //暴力
    for(int i=0;i<nums.length;i++){
       for(int j=i+1;j<nums.length;j++){
           if(target-nums[i]==nums[j]){
               System.out.println(i+","+j);
           }
       }
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-11-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案