LeetCode:Two Sum II
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的更多相关文章
- [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 ...
- 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 ...
- LeetCode: Combination Sum II 解题报告
Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all uni ...
- [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 ...
- [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 ...
- [LeetCode] Combination Sum II 组合之和之二
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- LeetCode Two Sum II - Input array is sorted
原题链接在这里:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ 题目: Given an array of intege ...
- [leetcode]Path Sum II @ Python
原题地址:https://oj.leetcode.com/problems/path-sum-ii/ 题意: Given a binary tree and a sum, find all root- ...
- LeetCode OJ--Path Sum II **
https://oj.leetcode.com/problems/path-sum-ii/ 树的深搜,从根到叶子,并记录符合条件的路径. 注意参数的传递,是否需要使用引用. #include < ...
随机推荐
- lucene全文检索---打酱油的日子
检索内容,一般的程序员第一时间想到的是sql的like来做模糊查询,其实这样的搜索是比较耗时的.已经有lucene帮我们 封装好了,lucene采用的是分词检索等策略. 1.lucene中的类描述 I ...
- 【原】PHP初体验
1. 相关内容介绍 1>互联网开发 互联网:传统互联网.移动互联网 互联网开发:前端开发(前台).后台开发(后端.服务端) 前端开发:视觉展示(用户界面).用户交互.采集输入信息 后台开发:管理 ...
- ZeroMQ接口函数之 :zmq_getsockopt – 获取ZMQ socket的属性
ZeroMQ API 目录 :http://www.cnblogs.com/fengbohello/p/4230135.html 本文地址 :http://www.cnblogs.com/fengbo ...
- 通过hexo+NexT构建静态博客
一般的教程网上有很多,主要讲下我遇到的问题以及解决方法: 一.hexo建立的文档无法上传github deploy: type: git repository: https://github.com/ ...
- 使用File类列出指定位置下的文件及目录信息
public static void main(String [] args) { File f=new File("C:"); File [] fl=f.listFiles(); ...
- 四则运算之Right-BICEP测试
Right-结果是否正确? 正确 B-是否所有的边界条件都是正确的? Conformance(一致性):值是否和预期的一致 是一致的 Ordering(顺序性):值是否如应该的那样 是 是有序或者无 ...
- antlr.collections.AST.getLine()I异常
antlr.collections.AST.getLine()I异常 Struts+hibernate+spring项目经常遇到问题 因为Struts自带的antlr-2.7.2.jar,比H ...
- GIT 操作
1. 查看某个文件某次提交修改的内容 git show commitid a.txt 2. git rm 和 git rm --cached 当我们需要删除暂存区或分支上的文件, 同时工作区也不 ...
- PHP 两个多维数组根据某个键的值进行组合排序的几种思路(二)
几个经过封装的方法: 1.使用 array_multisort() 函数 <?php $arr = [ ['name'=>'dee','age'=>28], ['name'=> ...
- php 读取文件
<?php /** *@param string $ip *@return string ip对应的地区 */ function getLocation($ip) { $ip_file_path ...