leetcode--Binary Tree Level Order Traversal II
来源:互联网 发布:卡五星源码 编辑:程序博客网 时间:2024/06/03 19:05
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.
题意:从下往上,将每一层从左往右存储
分类:二叉树
解法1:层次遍历,使用队列进行层次遍历,关键在于标记每一层结束的位置。使用了ceng来标记,每次low==ceng,说明该层遍历完毕,将ceng更新为当前high
解法2:层次遍历,而辨别层结束的方法是,在每层结尾,都添加一个标记元素,遍历时遇到标记元素,说明该层遍历结束
原文链接http://blog.csdn.net/crazy__chen/article/details/46378669
阅读全文
0 0
- LeetCode: Binary Tree Level Order Traversal II
- [LeetCode]Binary Tree Level Order Traversal II
- LeetCode Binary Tree Level Order Traversal II
- [Leetcode] Binary Tree Level Order Traversal II
- LeetCode Binary Tree Level Order Traversal II
- [LeetCode] Binary Tree Level Order Traversal II
- 【leetcode】Binary Tree Level Order Traversal II
- [LeetCode]Binary Tree Level Order Traversal II
- [Leetcode]Binary Tree Level Order Traversal II
- [leetcode]Binary Tree Level Order Traversal II
- LeetCode-Binary Tree Level Order Traversal II
- LeetCode - Binary Tree Level Order Traversal II
- [LeetCode] Binary Tree Level Order Traversal II
- LeetCode | Binary Tree Level Order Traversal II
- LeetCode - Binary Tree Level Order Traversal II
- 【leetcode】Binary Tree Level Order Traversal II
- 【LeetCode】Binary Tree Level Order Traversal II
- [LeetCode] Binary Tree Level Order Traversal II
- Qt函数库之QScrollBar类参考
- Git中.gitignore文件不起作用的解决以及Git中的忽略规则介绍
- ARM之按键中断
- 虚拟现实的发展历程
- 学习笔记【8月8日】
- leetcode--Binary Tree Level Order Traversal II
- 数据库主从分离
- ARM之定时中断
- hdu 6038 Function
- LaTeX文档插入图片的几种常用方法
- CentOS 7 开机加载内核模块
- 逻辑左移,算术左移,逻辑右移,算术右移
- final、finally和finalize的区别
- Oracle中having函数和in函数的用法