摘要: 这道题让我们求二叉树的坡度,某个结点的坡度的定义为该结点的左子树之和与右子树之和的差的绝对值,这道题让我们求所有结点的坡度之和. 这道题最好的解法应该是用后序遍历来做,因为后序遍历的顺序是左-右-根,那么就会从叶结点开始处理,这样我们就能很方便的计算结点的累加和,同时也可以很容易的根据子树和来计算t 阅读全文
posted @ 2017-07-31 22:07 apanda009 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 用的list.addFist(); 达到左右根的目的. 节点值在加的时候, 先判断是否为空. listNode 也是哦 阅读全文
posted @ 2017-07-31 21:42 apanda009 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 算法: 根右左, 尾递归 容器: list 尾递归 corner case: 右没有怎么办, 加一个输入值表示深度, list.size() 也表示深度 The core idea of this algorithm: 1.Each depth of the tree only select one 阅读全文
posted @ 2017-07-31 21:37 apanda009 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ext... 阅读全文
posted @ 2017-07-31 19:52 apanda009 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 三步反转法 阅读全文
posted @ 2017-07-31 15:43 apanda009 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 二有序数组常用二分法, 要判断数组是否越界, 而数组的题常用递归, 擦半的方法, 比快排的方法, 少一个partition 遍历, 但是还是分成logn 层, Lintcode: Nuts & Bolts Problem 关键在于找到合适的比较位置, 准备擦出哪个数组的一半, 防止数组越界 The 阅读全文
posted @ 2017-07-31 14:05 apanda009 阅读(140) 评论(0) 推荐(0) 编辑
摘要: sorted 数组, 常用二指针遍历, 会倒叙, 会前序 逆序遍历的好处, 1只遍历后面的 2此题在于空间上可以不干扰. 阅读全文
posted @ 2017-07-31 12:07 apanda009 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 有序数组的题, 二分法, 根据mid的位置再确定start 和end的位置, 画图分情况 三种情况 The idea is that when rotating the array, there must be one half of the array that is still in sorte 阅读全文
posted @ 2017-07-31 11:35 apanda009 阅读(173) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume NO duplicates in the array. ... 阅读全文
posted @ 2017-07-31 10:54 apanda009 阅读(112) 评论(0) 推荐(0) 编辑
摘要: while-loop 要非递归写很简单,就用循环, 如果很复杂,就要用递归. but while 容易死循环 看不出就画图 二分法的模板- 阅读全文
posted @ 2017-07-31 10:44 apanda009 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 两个数组两个指针 两个数组的题常sort, 再通过两指针遍历 常常与0 的差的正负来判断, 来判断指针的走位, 此处直接判断大小更方便 阅读全文
posted @ 2017-07-31 09:49 apanda009 阅读(132) 评论(0) 推荐(0) 编辑