35. Search Insert Position Description Given a sorted array and a target value, return the index if the target is found. If not, return the index wher ...
分类:
其他好文 时间:
2018-09-18 20:54:30
阅读次数:
154
Leetcode: 二叉树的前序遍历 最近在复习数据结构, 感觉很多东西都忘得的差不多了,哪怕是看完书再看视频,还是容易忘,所以干脆想着配合leetcode来刷吧,Python实现起来很简单,但是C语言也不能丢,所以C语言和Python一起吧。 题目: 给定一个二叉树,返回它的前序遍历。 Pytho ...
分类:
其他好文 时间:
2018-09-18 16:11:51
阅读次数:
136
原题目:Search for a Range, 现在题目改为: 34. Find First and Last Position of Element in Sorted Array Given an array of integers nums sorted in ascending order, ...
分类:
其他好文 时间:
2018-09-18 11:19:38
阅读次数:
197
题目链接 https://leetcode.com/problems/binary tree level order traversal/description/ 题目描述 给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。 例如: 给定二叉树: [3,9,20,nul ...
分类:
其他好文 时间:
2018-09-18 11:19:08
阅读次数:
173
判断该树是不是平衡的二叉树。如果某二叉树中任意结点的左右子树的深度相差不超过1,那么它就是一棵平衡二叉树。方法一:先序遍历 1.计算节点深度 2.递归判断是否平衡 上面的“先序遍历”判断二叉树平衡的方法,时间复杂度比较大。因为,二叉树中的很多结点遍历了多次。 方法二:后序遍历 ...
分类:
其他好文 时间:
2018-09-18 00:34:28
阅读次数:
150
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长。 思路: 这道题找出凸包上的点后,s数组中就是按顺序的点,累加一下距离就是周长了。 #include <algorith ...
分类:
其他好文 时间:
2018-09-18 00:19:31
阅读次数:
146
class Solution { public: TreeNode* invertTree(TreeNode* root) { if(root == NULL) return NULL; TreeNode* tmp = invertTree(root->left); root->left = inv... ...
分类:
其他好文 时间:
2018-09-17 16:15:39
阅读次数:
130
题目链接 https://leetcode.com/problems/unique binary search trees/description/ 题目描述 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 题解 首先定义一个函数G[n]:表示1...n构成的二叉搜 ...
分类:
其他好文 时间:
2018-09-17 13:28:35
阅读次数:
185
https://leetcode.com/problems/unique-binary-search-trees/discuss/31666/DP-Solution-in-6-lines-with-explanation.-F(i-n)-G(i-1)-*-G(n-i) ...
分类:
其他好文 时间:
2018-09-17 13:25:09
阅读次数:
123