解题思路:
广度遍历而且要记录每一层。广度遍历利用队列实现,记录用列表实现
使用一个列队,一个列表。 列队用于记录每一层节点,列表用于存储每一层的节点
Binary Tree Level Order Traversal Total Accepted: 51429 Total Submissions: 174478
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to rig...
分类:
其他好文 时间:
2015-06-03 10:03:00
阅读次数:
129
This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut...
分类:
其他好文 时间:
2015-06-03 00:54:17
阅读次数:
101
To be honest, this problem is designed to let you use stacks. However, I don't. In fact, you only need to keep a flagand switch it between falseandtru...
分类:
其他好文 时间:
2015-06-03 00:49:58
阅读次数:
232
This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut...
分类:
其他好文 时间:
2015-06-03 00:49:25
阅读次数:
132
This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut...
分类:
其他好文 时间:
2015-06-03 00:46:35
阅读次数:
131
Well, I do not see what this problem is for. The same code of Binary Tree Level Order Traversal can be used here. The only difference is that we shoul...
分类:
其他好文 时间:
2015-06-03 00:44:08
阅读次数:
209
This problem seems to be tricky at first glance. However, if you know Morris traversal, it is just the preorder case of Morris traversal and the code ...
分类:
其他好文 时间:
2015-06-03 00:42:17
阅读次数:
136
A classic tree traversal problem. I share my two solutions here: BFS and DFS.BFS: 1 vector> levelOrder(TreeNode *root) { 2 vector> levels;...
分类:
其他好文 时间:
2015-06-03 00:36:39
阅读次数:
161
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11' has binary representation 00000000...
分类:
其他好文 时间:
2015-06-02 22:04:54
阅读次数:
128
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101...
分类:
其他好文 时间:
2015-06-02 22:04:40
阅读次数:
166