leetcode Two Sum II - Input array is sorted <面试常考题>
题目描述
//二分查找的变形 用头尾两个指针进行 面试考察题
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
vector<int> ret;
if(numbers.size() == )
return ret;
int i = ;
int j = numbers.size() -; while(i < j){
if(numbers[i] + numbers[j] == target){
ret.push_back(i+);
ret.push_back(j+);
return ret;
}
if(numbers[i] + numbers[j] > target){
j--;
}
if(numbers[i] + numbers[j] < target){
i++;
}
}
return ret;
}
};
leetcode Two Sum II - Input array is sorted <面试常考题>的更多相关文章
- [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 Two Sum II - Input array is sorted
原题链接在这里:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ 题目: Given an array of intege ...
- Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted)
Leetcode之二分法专题-167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted) 给定一个已按照升序排列 的有序数组,找到两个数使得它们 ...
- 167. Two Sum II - Input array is sorted - LeetCode
Question 167. Two Sum II - Input array is sorted Solution 题目大意:和Two Sum一样,这里给出的数组是有序的 思路:target - nu ...
- 29. leetcode 167. Two Sum II - Input array is sorted
167. Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascendi ...
- 【LEETCODE】38、167题,Two Sum II - Input array is sorted
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- LeetCode_167. Two Sum II - Input array is sorted
167. Two Sum II - Input array is sorted Easy Given an array of integers that is already sorted in as ...
- leetcode2 Two Sum II – Input array is sorted
Two Sum II – Input array is sorted whowhoha@outlook.com Question: Similar to Question [1. Two Sum], ...
- 167. Two Sum II - Input array is sorted【easy】
167. Two Sum II - Input array is sorted[easy] Given an array of integers that is already sorted in a ...
随机推荐
- Immediate Decodability HDU - 1305(模板trie)
求这些01串是否有一个是另一个的前缀.. 就是求次数就好了嘛...emm... 网上竟然都用指针写.... #include<cstdio> #include<iostream> ...
- TCP/IP四层协议模型与ISO七层模型
TCP/IP四层协议模型与ISO七层模型 在世界上各地,各种各样的电脑运行着各自不同的操作系统为大家服务,这些电脑在表达同一种信息的时候所使用的方法是千差万别.就好像圣经中上帝打乱了各地人的口音,让他 ...
- hbase 安装笔记
1.安装 在官方镜像站点下载hbase2.0,地址:https://www.apache.org/dyn/closer.lua/hbase/ 解压tar xzvf hbase-2.0.4-bin.ta ...
- Bootstrap 环境安装
下载 Bootstrap 可以从 http://getbootstrap.com/ 上下载 Bootstrap 的最新版本.当点击这个链接时,将看到如下所示的网页: 您会看到两个按钮: Downloa ...
- 【MediaElement】WPF视频播放器【1】
一.前言 前两天上峰要求做一个软件使用向导,使用WPF制作.这不,这两天从一张白纸开始学起,做一个播放演示视频的使用向导.以下是粗设计的原型代码: 二.效果图 三.代码 前台代码: < ...
- 【CF375C】Circling Round Treasures
Portal --> CF375C Solution 一个有趣的事情:题目中有很大的篇幅在介绍如何判断一个位置在不在所围的多边形中 那么..给了方法当然就是要用啊 首先是不能包含\('B'\ ...
- 小Q与内存
Portal --> broken qwq Description (这个描述好像怎么都精简不起来啊qwq) 大概是说你的计算机有1GB的物理内存,按照Byte寻址,其物理地址空间为\(0\si ...
- Codeforces Round #384 (Div. 2) A B C D dfs序+求两个不相交区间 最大权值和
A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 洛谷P1195 口袋的天空
口袋的天空 327通过 749提交 题目提供者该用户不存在 标签云端 难度普及+/提高 时空限制1s / 128MB 提交 讨论 题解 最新讨论更多讨论 暂时没有讨论 题目背景 小杉坐在教室里,透 ...
- 手脱nSPack 3.7
方法一: 1. OD查壳—nSpack3.7的壳 2. 载入OD 看起来很眼熟,F8一次,然后下面就可以使用ESP定律了,使用ESP定律下断点,然后F9四次 3. F9四次后落到这个位置 接下 ...