Two Sum
2016-05-07 00:00
369 查看
摘要: Two Sum leecode
本来想排个序,直接搜索就过了,复杂度O(n*n)。
参考网站:1、题目网站:https://leetcode.com/problems/two-sum/
2、vector操作网站:http://blog.csdn.net/phoebin/article/details/3864590
本来想排个序,直接搜索就过了,复杂度O(n*n)。
class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> res(2,0); //sort(nums.begin(), nums.end()); int length = int(nums.size()); int tmp = 0; for (int i=0; i<length; i++) { tmp = target-nums[i]; for (int j=i+1; j<length; j++) { if (nums[j]==tmp) { res[0]=i; res[1]=j; return res; } } } return res; } };
参考网站:1、题目网站:https://leetcode.com/problems/two-sum/
2、vector操作网站:http://blog.csdn.net/phoebin/article/details/3864590
相关文章推荐
- mysql中sum float类型使用小数点的方法
- Mysql中的count()与sum()区别详细介绍
- MySQL中的SUM函数使用教程
- 【python】编程学习练习题-2
- LeetCode 2: Add Two Numbers (JAVA)
- LeetCode 3: Longest Substring Without Repea (JAVA)
- Leetcode 编程训练
- Path Sum
- 1001
- LeetCode: 关于Sum的题目合集
- Add Two Numbers
- ORACLE的 SUM()OVER()函数的使用1
- Two Sum
- Sum of Consecutive Prime Numbers
- Median of Two Sorted Arrays
- Two Sum
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- COBOL入门
- 开篇启示