leetcode
东方still未明
这个作者很懒,什么都没留下…
展开
-
Game of Life
看到discussion里的,想明白了,写一下自己的想法和经验。 这道题如果英语不好的话首先试题目不好懂 Any live cell with fewer than two live neighbors dies, as if caused by under-population.Any live cell with two or three live neighbors lives原创 2016-05-25 20:31:26 · 450 阅读 · 0 评论 -
House Robber
这道题的意思是任何两个相连接的点不能同时被盗。 所以使用递归就可以了,需要记录每个节点的两种情况: result数组中存的是每个节点算上自己的当前节点的值result[1]和不算自己当前节点的值reslut[0]的情况。 1、不算自己节点,将比较 (node.left)左孩子 算左节点自己节点和 不算左节点自己节点的,去这两种的最大值,然后在同样比较右节点(node.righ原创 2016-06-24 17:34:04 · 398 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Tree
思路为: 找到p,q,的节点,利用递归从而找到p,q的共公父节点,返回的父节点即为所求的节点 public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root== null) return null; if(root==p) return root; els原创 2016-06-05 10:38:03 · 299 阅读 · 0 评论