当前位置:网站首页>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)
边栏推荐
- MySQL shutdown is slow
- VLSM variable length subnet mask partition tips
- 平衡二叉树详解 通俗易懂
- GNSS positioning accuracy index calculation
- [rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
- 分支语句和循环语句
- 几道高频的JVM面试题
- KF UD分解之UD分解基础篇【1】
- Fgui project packaging and Publishing & importing unity & the way to display the UI
- GNSS定位精度指标计算
猜你喜欢
【无标题】
系统设计学习(一)Design Pastebin.com (or Bit.ly)
记录:初次cmd启动MySQL拒接访问之解决
121道分布式面试题和答案
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
Heap sort [handwritten small root heap]
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
[算法] 剑指offer2 golang 面试题2:二进制加法
C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
国企秋招经验总结
随机推荐
Devops' future: six trends in 2022 and beyond
Mixed use of fairygui button dynamics
Iterable、Collection、List 的常见方法签名以及含义
[rtklib 2.4.3 B34] version update introduction I
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
Record: solution of 404 error of servlet accessing database in dynamic web project
最短Hamilton路径 (状压DP)
服务未正常关闭导致端口被占用
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
How do architects draw system architecture blueprints?
FairyGUI条子家族(滚动条,滑动条,进度条)
How to improve the deletion speed of sequential class containers?
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
架构师怎样绘制系统架构蓝图?
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
Detailed explanation of balanced binary tree is easy to understand
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
Error: sorting and subscript out of bounds