leetcode 167[easy]---Two Sum II
来源:互联网 发布:如何骂淘宝天下小二 编辑:程序博客网 时间:2024/05/02 00:17
难度:easy
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution and you may not use the same element twice.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
思路:题意简单,找到给定list的两个数,这两个数的和等于target,并以list的形式返回index。发现在leetcode中用index()好像不行。
双支针的方法,从头尾向中间走,直到两指针的和为target。
阅读全文
0 0
- leetcode 167[easy]---Two Sum II
- Leetcode[Easy] - Two Sum
- 【Leetcode】Two sum(easy)
- leetcode Two Sum easy
- Leetcode #167 Two Sum II
- Leetcode 167 Two Sum II
- LeetCode 167 Two Sum II
- LeetCode[167]Two Sum II
- LeetCode-167:Two Sum II
- leetcode 167--- Two Sum II
- LeetCode #167 Two Sum II
- 【Leetcode】Two Sum II #Too easy, just review hashmap
- [leetcode] Two Sum II
- LeetCode : Two Sum II
- leetcode [Two Sum II
- 【LeetCode】Two Sum II
- 【leetcode】Two Sum II
- LeetCode:Two Sum II
- ionic3开发系列——实现对手机软件键盘按键的监听
- 单隐层神经网络拟合任意函数
- 【人工智能工程师】掌握这10个项目,秒杀90%面试者!
- python的requests快速上手、高级用法和身份认证
- 对gulp-changed插件的一点思考
- leetcode 167[easy]---Two Sum II
- Java的构造方法链
- Java Socket编程和TCP/IP协议
- git的分支管理
- Redis新特性GEOHASH
- laravel项目登录不了的问题
- linux cpufreq framework(3)_cpufreq core
- 一派胡言!敢说我们程序员是出轨率最高的群体?
- 焦点设置 (一)