当前位置:网站首页>167. Sum of two numbers II - input ordered array - Double pointers
167. Sum of two numbers II - input ordered array - Double pointers
2022-07-06 13:05:00 【The_ Dan】
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int left = 0, right = numbers.size() - 1;
while(left < right){
if(numbers[left] + numbers[right] == target)
return {
left + 1, right + 1};
while(numbers[left] + numbers[right] > target) // use while Can improve efficiency
right--;
while(numbers[left] + numbers[right] < target)
left++;
}
return {
-1, -1};
}
};
Accepted
21/21 cases passed (8 ms)
Your runtime beats 28.77 % of cpp submissions
Your memory usage beats 5.03 % of cpp submissions (15.3 MB)
边栏推荐
- 【干货】提升RTK模糊度固定率的建议之周跳探测
- MySQL shutdown is slow
- [算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
- 异常:IOException:Stream Closed
- One article to get UDP and TCP high-frequency interview questions!
- Chromatic judgement bipartite graph
- 服务未正常关闭导致端口被占用
- GNSS positioning accuracy index calculation
- 阿里云微服务(四) Service Mesh综述以及实例Istio
- wsl常用命令
猜你喜欢

2-year experience summary, tell you how to do a good job in project management

FGUI工程打包发布&导入Unity&将UI显示出来的方式
![[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和](/img/17/e7c9bfa867030af97eb66a7932c7e3.png)
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和

面渣逆袭:Redis连环五十二问,三万字+八十图详解。

rtklib单点定位spp使用抗差估计遇到的问题及解决

MySQL shutdown is slow

Music playback (toggle & playerprefs)

服务未正常关闭导致端口被占用

Role movement in the first person perspective

Liste des boucles de l'interface graphique de défaillance
随机推荐
NovAtel 板卡OEM617D配置步骤记录
错误: 找不到符号
Excel导入,导出功能实现
抽象类和接口
One article to get UDP and TCP high-frequency interview questions!
Fairygui loop list
Edit distance (multi-source BFS)
GNSS positioning accuracy index calculation
记录:动态Web项目servlet访问数据库404错误之解决
【GNSS】抗差估计(稳健估计)原理及程序实现
What are the functions and features of helm or terrain
Wechat applet development experience
Error: sorting and subscript out of bounds
XV Function definition and call
VLSM variable length subnet mask partition tips
How to ensure data consistency between MySQL and redis?
KF UD decomposition pseudo code implementation advanced [2]
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
[GNSS] robust estimation (robust estimation) principle and program implementation
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现