167. Two Sum II - Input array is sorted

Posted 阿怪123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了167. Two Sum II - Input array is sorted相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/

package com.company;

public class Solution {
    public int[] twoSum(int[] numbers, int target) {
        int len=numbers.length;
        if(len==0||len==1)
            return null;
        int[] res=new int[2];
        int right=len-1;
        int left=0;
        while(left<right)
        {
            if(numbers[left]+numbers[right]==target)
            {
                res[0]=left+1;
                res[1]=right+1;
                break;
            }
            else  if(numbers[left]+numbers[right]>target)
            {
                right--;
            }
            else
            {
                left++;
            }
        }
        return res;
    }
}

 

以上是关于167. Two Sum II - Input array is sorted的主要内容,如果未能解决你的问题,请参考以下文章

167. Two Sum II - Input array is sorted

167. Two Sum II - Input array is sortedeasy

167. Two Sum II - Input array is sorted

LeetCode167. Two Sum II - Input array is sorted

167. Two Sum II - Input array is sorted

167.Two Sum II–Input is sorted