167. Two Sum II
来源:互联网 发布:北京网络职业学院搬迁 编辑:程序博客网 时间:2024/05/23 01:23
class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { vector<int> ans; int ending = numbers.size() - 1; int temp; for(int i = 0; i <= ending; ++i){ int toFound = target - numbers[i]; int temp = search(numbers, i+1, ending, toFound); if(temp != -1){ ans.push_back(i+1); ans.push_back(temp+1); break; } } return ans; } int search(vector<int> &n, int low, int high, int target){ while(low <= high){ int mid = (low + high) / 2; if(n[mid] == target){ return mid; } else if(n[mid] > target) high = mid - 1; else low = mid + 1; } return -1; } };
阅读全文
0 0
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 167. Two Sum II
- 常用控件
- 8.20 北校 复习
- C/C++的变量生存期和作用域
- solr全文检索
- iOS title view不居中的处理办法
- 167. Two Sum II
- Android和js交互
- Android 程序多语言国际化
- Zookeeper分成多组注册中心
- 通过创建方法,减少不同浏览器通过JS设置样式时的重复书写
- Linux环境获取系统配置信息
- The Tower of Babylon (DAG最长路算法模板)
- Java帝国之宫廷内斗
- C语言实现 从尾到头打印链表每个节点的值(链表学习 二)