- 博客(8)
- 收藏
- 关注
原创 [LeetCode]11. Container With Most Water解法及python
原题链接:https://leetcode.com/problems/container-with-most-water 最开始的想法是O(n2n2n^2)的,即暴力的双层循环,比较哪两条线围成的梯形或矩形能装最多的雨水(容量视短线而定),但提交后超时,就寻找更为优化的方法。 之后的想法是先锁定长方形的最大宽度len(height)-1,计算maxArea,然后再更改low或high中边较短的...
2018-03-04 19:34:52
345
原创 [LeetCode]10. Regular Expression Matching的DP理解及代码
原题链接:https://leetcode.com/problems/regular-expression-matching/ 先上代码:(由于我的DP很渣,这份代码并非自己写的,而是摘自这道题的Discuss中的分享), 链接:https://leetcode.com/problems/regular-expression-matching/discuss/5678/Fast-Python-...
2018-03-02 22:08:21
418
原创 [LeetCode]563. Binary Tree Tilt解法及python代码
原题链接:https://leetcode.com/problems/binary-tree-tilt/ 先来了解一下Tilt的描述,原题的描述是The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of a
2018-02-02 14:38:59
438
原创 [LeetCode]669. Trim a Binary Search Tree解法及python代码
原题链接:https://leetcode.com/problems/trim-a-binary-search-tree/ 这个题描述中给的是平衡二叉树,利用平衡二叉树性质,当前节点的值小于L时,这个节点的左子树都小于L,可以剪掉,并用右子树代替当前节点;当前节点的值大于R时,这个节点的右子树都大于R,可以剪掉,并用左子树代替当前节点。代码如下: class Solution(object):
2018-01-25 15:59:01
374
原创 [LeetCode]671. Second Minimum Node In a Binary Tree解法及python代码
原题链接:https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/ 这个题的树有两个特点,一个是树如果有儿子一定有两个,另一个是根节点的值是根、左、右三个节点值最小的点。最开始的想法是基于先序遍历在树的遍历过程中剪枝,但发现这种方法在递归过程中比较难实现,就使用了另外一种办法:先序遍历整个树,在遍历过程中将值加入set
2018-01-24 23:31:13
282
原创 [集群配置]macOS Flume+kafka单机安装连接
Flume-agent内部架构: 1. 下载flume及kafka 地址:http://flume.apache.org/ 版本:apache-flume-1.8.0-bin.tar.gz 地址:http://kafka.apache.org/ 版本:kafka_2.11-1.0.0.tgz 2. 解压及移动 解压文件并移动到自己熟悉的位置,我的kafka和flume都放在/
2018-01-24 19:57:44
781
原创 [LeetCode]12. Integer to Roman解法及python代码
原题链接:https://leetcode.com/problems/integer-to-roman 这个题我最开始的想法很简单,由于限制输入在1~3999之间,所以可以写出1~10,10~3999间的能整除10的数的罗马数字,对于输入使用整数除法以及求余处理就可以O(1)的得到结果,下面代码: class Solution(object): def intToRoman1(se
2018-01-21 13:54:59
355
原创 [LeetCode]34. Search for a Range解法及python代码
原题链接:https://leetcode.com/problems/search-for-a-range 看到时间复杂度O(logN)之后的第一想法就是二分法,这道题的想法是二分法的一种变种: 1. 递归出口: end-start 2. 计算mid位置 3. 如果mid==target,递归调用函数向左右扩展(左右都有可能会有target值)。 如果mid <
2018-01-21 13:39:15
441
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人