中级农民
- 积分
- 106
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2019-1-17
- 最后登录
- 1970-1-1
|
坚持第11天, 刷了3题
1. In each iteration, we add to queue all of nodes of a level (right and left node of all the last level nodes), rightmost node is always the first one in the queue (i=0). (Also will poll out the old node in last level)
2. new ArrayList(),不是new List().即使是List<Integer>
3. i<size而不是i<queue.size(). 注意for loop每次都会poll out a node, 所以quue.size()会变,所以必须提前define一个integer防止之后改变!
4. 这里我个人优化了一下,只加入rightmost node's children, so no need to add all the nodes in a level anymore。 但是错误!因为最后一层可能只有最左边一个节点, 那么这个节点也是rightmost.所以不能只加右节点。So you must add all the nodes in a level!
5. Merge Sort: O(nlogn) time comlexity. it is divide and conquer: divides the problem into subproblems, sorts them individually, and merges them back together at the end.
6.Divide a LinkedList into two parts. When fast pointer reaches the end, slow pointer is in the middle, and temp is still at the beginning. That's why we need three pointers. |
|