leetcode mock interview-two sum II

Posted 笨鸟居士的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode mock interview-two sum II相关的知识,希望对你有一定的参考价值。

package com.company;


import java.util.LinkedList;
import java.util.List;

public class Main {

    public int[] twoSum(int[] numbers, int target) {
        int i = 0, j = numbers.length - 1;
        int []ret = new int[2];
        while (i < j) {
            if (numbers[i] + numbers[j] < target) {
                i++;
            }
            else if (numbers[i] + numbers[j] > target) {
                j--;
            }
            else {
                ret[0] = i+1;
                ret[1] = j+1;
                break;
            }
        }
        return ret;
    }



    public static void main(String[] args) {
        // write your code here
        System.out.println("Hello");

        int []numbers = {2, 7, 11, 15};
        int target = 9;
        Main mn = new Main();
        int[] ret = mn.twoSum(numbers, target);
        System.out.printf("ret: %d, %d\n", ret[0], ret[1]);

    }
}

 

以上是关于leetcode mock interview-two sum II的主要内容,如果未能解决你的问题,请参考以下文章

word-pattern(mock)

binary-tree-maximum-path-sum(mock)

mock模拟响应

Mock简明文档

[分享] 利用 ApiPost 生成mock数据

Python中使用mock.Mock()进行mock测试