同样,使用两个队列进行层间循环和层内循环。最后使用一个栈进行转置。PS:特别注意的是,对于vector的使用,在赋值的阶段会发生内存报错的情况:vector vec1;vec1[0]=1直接使用下标赋值是错误的,应使用的是push_back()函数进行数值添加。而,在调用已经赋值的变量时,可以使用下...
分类:
其他好文 时间:
2015-07-08 12:21:56
阅读次数:
97
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next() will return the next smallest number in the BST.
Note: next()...
分类:
其他好文 时间:
2015-07-07 22:50:37
阅读次数:
208
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
分类:
其他好文 时间:
2015-07-07 18:44:59
阅读次数:
83
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray...
分类:
其他好文 时间:
2015-07-07 16:53:37
阅读次数:
108
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
分类:
其他好文 时间:
2015-07-07 16:30:04
阅读次数:
127
1. 问题描述 给定一个二叉搜索树,找出第k小的元素。注意:可以假设k总是存在,1≤k≤BST总元素数1 \le k \le BST总元素数。2. 方法与思路 根据二叉搜索树的特点,中序遍历的结果即是排序好的数组。那么找出第k小的数,只需要先进行一次中序遍历即可。
/**
* Definition for a binary tree node.
* struct TreeNode {...
分类:
其他好文 时间:
2015-07-07 13:09:15
阅读次数:
119
ueventd主要是负责设备节点的创建、权限设定等一些列工作。服务通过使用uevent,监控驱动发送的消息,做进一步处理。
ueventd实际和init是同一个binary,只是走了不同分支,可参看前一部分。
ueventd的整体代码比较简单,主要是三部分:
解析ueventd.rc 初始化设备信息 循环polling uevent消息
主函数及相关功能如下如下:
int ue...
分类:
移动开发 时间:
2015-07-07 13:04:59
阅读次数:
195
递归算法 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * ...
分类:
其他好文 时间:
2015-07-07 12:54:12
阅读次数:
107
定义
二叉树(binary tree)是n(n>=0)个结点的有限集合,该集合为空集合称为空二叉树,或者有一个根结点和两棵互不相交的,分别称为树根结点的左孩子树和右孩子树组成.
二叉树的特点
每个结点最多有两棵子树,所以二叉树总没有度大于2的结点
左子树和右子树是有顺序的,次数不能任意颠倒
即使树中某结点只有一棵子树,也要区分是左子树还是右子树
特殊的二叉树1. 斜树...
分类:
其他好文 时间:
2015-07-07 09:40:05
阅读次数:
170
题解:
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
For example:
Given binary tree {3,9,20,#,#,15,7},
3
/ 9...
分类:
编程语言 时间:
2015-07-07 09:39:22
阅读次数:
109