标签:
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
标签:
原文地址:http://www.cnblogs.com/charlesblc/p/5936948.html