博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Two Sum
阅读量:6932 次
发布时间:2019-06-27

本文共 727 字,大约阅读时间需要 2 分钟。

hot3.png

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].
class Solution {public:    vector
twoSum(vector
& nums, int target) { int n = nums.size(); for (int i = 0; i < n; ++ i) { for (int j = i + 1; j < n; ++ j) { if (target == nums[i] + nums[j]) { return {i, j}; } } } return nums; }};

 

转载于:https://my.oschina.net/gonglibin/blog/1616830

你可能感兴趣的文章
我的友情链接
查看>>
Windows常用的快捷方式
查看>>
CentOS6.4安装Oralce11.2问题总结
查看>>
mysql分区技术
查看>>
跳出当前for循环
查看>>
IDEA java开发学习笔记
查看>>
欢迎大家关注我的微信公账号
查看>>
git学习心得总结
查看>>
猫猫学IOS(三十二)UI之Quartz2D矩阵操作和图片剪切
查看>>
ABBYY FineReader利用模式提高OCR质量
查看>>
代码的编写之惨烈的教训一
查看>>
Git之提交项目到远程github
查看>>
python一中实现组合的方式
查看>>
防火墙技术 配置基于上下文的访问控制
查看>>
简单字符串匹配方法
查看>>
linux安装及管理程序
查看>>
salt源码安装
查看>>
王高利:Kvm虚拟化(3)__nat方式上网
查看>>
我的友情链接
查看>>
linux中echo输出命令
查看>>