001.Two Sum[E] Two SumE 题目 思路 1双重循环 2 排序 3 Hashmap 1.题目 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. Example: Given nums = [2…
前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example…
39. Combination Sum Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. N…
在LeetCode做的第一到题 题目大意:给出n个数,在其中找出和为一个特定数的两个数. Input: numbers={2, 7, 11, 15}, target=9Output: index1=1, index2=2 返回这两个数在原数组内的下标. 我的思路: 1.遍历数组 int temp = target-num[i] 2.查找数组内有没有符合的temp存在. 3.因为这个题目是肯定会有符合条件的两个数的,所以temp肯定存在. 但这样会遇到这些问题: 1.查找最快的是使用二分查找,但是…
1.题目描述 2.问题分析 使用hashTable 寻找,target  -  num[i] ,将时间复杂度降低到 O(n): 3.代码 vector<int> twoSum(vector<int>& nums, int target) { map<int ,int> m; ; i < nums.size() ; ++i ){ m[nums[i]] = i; } vector<int> result; ; i < nums.size()…
1.题目描述 2.题目分析 考虑使用hashMap的方式将数组中的每个元素和下表对应存储起来,然后遍历数组,计算target 和 数组中每个元素的差值,在hashMap中寻找,一直到找到最后一对. 3.代码 vector<int> twoSum(vector<int>& nums, int target) { vector<int> ans; unordered_multimap<int,int> m; ; i< nums.size() ; i…
方法一:双指针 解题思路 假设链表存在相交时,headA 的长度为 a + c,headB 的长度为 b + c.如果把 headA 连上 headB,headB 连上 headB 的话,当遍历这两个新链表时有: \[(a + c) + (b + c) = (b + c) + (a + c) \] 而 \(a + c + b = b + c + a\),就出现相交的位置,因为 c 是相交部分的长度. 假设链表不相交,那么最后也会"相交","相交"于链表的尾部,即 n…
1. 题目 1.1 英文题目 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You c…
前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number…
前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers suc…