1-TwoSum(简单)

博客围绕给定整数数组,找出两数之和等于特定目标值的元素下标问题展开。强调同一元素不可重复使用,介绍了暴力遍历和哈希查找两种解法,分析了时间和空间复杂度,还给出C++数组长度、STL相关及迭代器使用的参考链接。

Description:

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].

Attention:

同一个元素不可重复使用,如 6 = 3 + 3:两个3必须是下标不同的元素。

Answer:

 

Review:

1、暴力遍历 时间复杂度O(n2),空间复杂度O(1)

2、哈希查找 时间复杂度O(n),空间复杂度O(n),空间换取时间

3、C++数组长度:参考 https://www.cnblogs.com/liutongqing/p/7282528.html

4、STL   vector<> 参考 https://www.cnblogs.com/aminxu/p/4686332.html

5、STL map<type,type> 参考 https://www.cnblogs.com/empty16/p/6395813.html

6、迭代器使用 参考 https://www.cnblogs.com/maluning/p/8570717.html

转载于:https://www.cnblogs.com/lsh0908/p/10554936.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值