当前位置:网站首页>6. Double pointer -- the sum of the two numbers of the incremental array is equal to the target number
6. Double pointer -- the sum of the two numbers of the incremental array is equal to the target number
2022-07-28 10:16:00 【[email protected]】
public int[] twoSum(int[] nums, int target) {
int low = 0, high = nums.length-1;
while(low < high){
int sum = nums[low] + nums[high];
if(sum < target) low++;
else if(sum >target) high--;
else return new int[] { nums[low], nums[high]};
}
return new int[0];
}
Running results :
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958224607.html
边栏推荐
- Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
- Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
- Flink - checkpoint Failure reason: Not all required tasks are currently running
- 网易笔试之不要二——欧式距离的典型应用
- Massive data topn problem
- [cloud co creation] enterprise digital transformation, Huawei cloud consulting is with you
- ELK实时日志分析平台
- [esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
- matlab特征点提取--记录自用
- a different object with the same identifier value was already associated with the session
猜你喜欢

Voice chat app - how to standardize the development process?

Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!

What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system

Arthas tutorial

7、二分法——寻找一组重复或者有序但是旋转的数组

初识SuperMap iDesktop

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?

14、双指针——盛最多水的容器

Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment

Redis面试题必知必会
随机推荐
Elk real time log analysis platform
LIBCMTD.lib
Prometheus operation and maintenance tool promtool (IV) TSDB function
初识SuperMap iDesktop
Status Notice ¶
Kubernetes
Lucene 查询语法备忘
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
PHP生成二维码(学习)
4.调整数组顺序使奇数位于偶数前面
配置树莓派,过程和遇到问题
Skillfully use NGX_ Lua makes traffic grouping
Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
[jzof] 15 bits of 1 in binary
什么样的知识付费系统功能,更有利于平台与讲师发展?
不登高山,不知天之高也;不临深溪,不知地之厚也
Aqua Data Studio 18.5.0导出insert语句
8、数组中出现次数超过一半的数字
uni-app进阶之生命周期
海量数据TopN问题