public class Solution {
public int[] twoSum(int[] numbers, int target) {
int left = 0;
int right = numbers.length - 1;
while (left < right) {
int sum = numbers[left] + numbers[right];
if (sum == target) {
return new int[]{left + 1, right + 1};
}
else if (sum < target) {
left++;
}
else right--;
}
return new int[]{0, 0};
}
}

LeetCode:Two Sum II的更多相关文章

  1. [leetcode]Path Sum II

    Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals ...

  2. LeetCode: Path Sum II 解题报告

    Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals ...

  3. LeetCode: Combination Sum II 解题报告

    Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all uni ...

  4. [LeetCode] Two Sum II - Input array is sorted 两数之和之二 - 输入数组有序

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  5. [LeetCode] Path Sum II 二叉树路径之和之二

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  6. [LeetCode] Combination Sum II 组合之和之二

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  7. LeetCode Two Sum II - Input array is sorted

    原题链接在这里:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ 题目: Given an array of intege ...

  8. [leetcode]Path Sum II @ Python

    原题地址:https://oj.leetcode.com/problems/path-sum-ii/ 题意: Given a binary tree and a sum, find all root- ...

  9. LeetCode OJ--Path Sum II **

    https://oj.leetcode.com/problems/path-sum-ii/ 树的深搜,从根到叶子,并记录符合条件的路径. 注意参数的传递,是否需要使用引用. #include < ...

随机推荐

  1. Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)

    org.apache.jasper.JasperException:xxx.jsp(1,1) Page-encoding specified in XML prolog (UTF-8) is diff ...

  2. IDE-Sublime【2】-代码智能提示插件SublimeCodeIntel的安装

    一.打开菜单References -> Package Control 二.输入Package Control: install Package,回车 三.输入SublimeCodeIntel, ...

  3. apace日常操作和配置

    [root@limt modules]# /usr/sbin/apachectl -h Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file ...

  4. 【Alpha】Daily Scrum Meeting第六次

    一.本次Daily Scrum Meeting主要内容 各队员的任务完成情况 接下去要做的任务有哪些方面的问题 二.项目进展 学号尾数 今日已完成任务 接下去要做 502 统一Excel表头数据的英文 ...

  5. C++ 画星号图形——空心梯形(核心代码记录)

    b=a; ;c<=a;c++) { ;d<=a-c;d++) printf(" "); ;e<=b;e++) ||c==a) printf("*&quo ...

  6. mango框架中表分片与数据库分片(分表与分库)

    表分片 表分片通常也被称为分表,散表. 当某张表的数据量很大时,sql执行效率都会变低,这时通常会把大表拆分成多个小表,以提高sql执行效率. 我们将这种大表拆分成多个小表的策略称之为表分片. 先来看 ...

  7. eclipse如何快速查找某个类

    2. [Ct rl+Shift +T ]    查找工作空间(Workspace)构建路径中的可找到Java类文件,不要为找不到类而痛苦,而且可以使用“*”.“?”等通配符. 3. 当我们编写了很多的 ...

  8. Thinking in Java——笔记(16)

    Arrays Why arrays are special There are three issues that distinguish arrays from other types of con ...

  9. 一起来做webgame,《Javascript蜘蛛纸牌》

    不得不说,做游戏是会上瘾的,这次带来的是win系统上的经典游戏<蜘蛛纸牌>,不能完美,但求一玩 移牌 0 次 Javascript game_蜘蛛纸牌 正在努力加载... // " ...

  10. 2在HTML中使用JavaScript

    像HTML页面中插入JavaScrip的主要方法,就是使用<script>元素.HTML4.01为<script>定义了6个属性:async:可选,表示应该立即下载脚本,当不妨 ...