![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode算法题
文章平均质量分 54
Reid__
这个作者很懒,什么都没留下…
展开
-
leetcode : twosum(使用哈希表)
给定一个int型一维数组,和一个目标值target,用一个int型一维数组返回数组中每一对相加等于target的的键值的index。具体函数如下:#include #include #include using namespace std;vector twosum(vector& nums,int &target){ unordered_map m; //用哈希表原创 2017-08-28 01:09:32 · 328 阅读 · 0 评论 -
leetcode : threesum
题目:从一个一维整型数组nums中找出所有能使x+y+z=0的解[x,y,z],并用一个二维数组输出。思路:给输入数组排序,然后遍历数组,把每次取出的元素作为可能解的最小元素x,在这个元素之后的序列中找能够使上式成立的所有(y,z)然后组合输出(x,y,z)。代码:#include using namespace std;vector> threeSum原创 2017-08-28 22:38:34 · 379 阅读 · 0 评论 -
leetcode : mergeTrees(递归)
题:输入两颗二叉树,将它们合成为一颗二叉树,合成规则如下,The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tr原创 2017-08-29 21:03:54 · 575 阅读 · 0 评论 -
leetcode : twosum/BST
题:判断二叉树中是否有满足x+y=target的整数对(x,y)代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x)原创 2017-08-29 19:25:11 · 256 阅读 · 0 评论 -
leetcode : subtree of another tree
题:给出两棵二叉树,判断一颗是不是另一颗的子树代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NU原创 2017-08-29 23:14:06 · 267 阅读 · 0 评论 -
leetcode : addTwoNum
题:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return转载 2017-08-31 23:52:35 · 1033 阅读 · 0 评论