Binary Tree Level Order Traversal II 从下向上按层遍历二叉树
来源:互联网 发布:ultrawebgrid绑定数据 编辑:程序博客网 时间:2024/05/16 06:57
Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For example:
Given binary tree {3,9,20,#,#,15,7}
,
3 / \ 9 20 / \ 15 7
return its bottom-up level order traversal as:
[ [15,7], [9,20], [3]]
confused what "{1,#,2,3}"
means? > read more on how binary tree is serialized on OJ.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector<vector<int> > levelOrderBottom(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<vector<int> > vec; queue<TreeNode *> cur; if(root==NULL) return vec; cur.push(root); vector<int> vv; queue<TreeNode *> next; while(!cur.empty()) { TreeNode *t = cur.front(); cur.pop(); vv.push_back(t->val); if(t->left) next.push(t->left); if(t->right) next.push(t->right); if(cur.empty()) { vec.insert(vec.begin(),vv);//vv从头插入 // cur=next; //next.clear(); swap(cur,next); vv.clear(); } } return vec; }};
0 0
- Binary Tree Level Order Traversal II 从下向上按层遍历二叉树
- 107. Binary Tree Level Order Traversal II (二叉树由底向上层次遍历)
- Binary Tree Level Order Traversal II 二叉树的反向层序遍历
- 二叉树的层序遍历 改进版 Binary Tree Level Order Traversal II
- Binary Tree Level Order Traversal II 二叉树的同层遍历系列2
- 004-107-Binary Tree Level Order Traversal II 层序遍历二叉树之二
- 【leetcode 层序遍历】Binary Tree Level Order Traversal II
- [leetcode-二叉树层次遍历并统计每层节点数]--107. Binary Tree Level Order Traversal II
- Binary Tree Level Order Traversal II 从底部倒着输出二叉树每一层的元素
- 70.Binary Tree Level Order Traversal II-二叉树的层次遍历 II(中等题)
- Binary Tree Level Order Traversal II(层次遍历二叉树II)
- [Lintcode]Binary Tree Level Order Traversal II 二叉树的层次遍历 II
- leetcode---binary-tree-level-order-traversal-ii---树层次遍历
- leetCode解题报告之Binary Tree Level Order Traversal II,I(二叉树层次遍历)
- Binary Tree Level Order Traversal II 二叉树层次遍历(广搜,queue)(重重)
- LeetCode OJ 之 Binary Tree Level Order Traversal II (二叉树的层次遍历-二)
- Leetcode Binary Tree Level Order Traversal II 二叉树分层遍历
- 107.LeetCode Binary Tree Level Order Traversal II(easy)[二叉树层次遍历 广度搜索 队列]
- [汇文教育]iOS内支付(IAP)研究
- Maximum Depth of Binary Tree 二叉树的最大深度
- MySQl命令
- mongodb 增加管理员及普通用户
- VC对话框大小和位置设置
- Binary Tree Level Order Traversal II 从下向上按层遍历二叉树
- A program to compute word length of a machine
- iOS中动画实现技术主要是:Core Animation。
- [csu oj]1553: Good subsequence(水题)
- Coursera上Andrew Ng机器学习课程总结(一)
- Balanced Binary Tree 平衡二叉树的判断
- String to Integer
- [图像]摄像机标定(2) 张正友标定推导详解
- Thinkphp学习笔记