leetcode刷题,总结,记录,备忘 107
来源:互联网 发布:老男孩linux运维2017 编辑:程序博客网 时间:2024/05/20 09:10
leetcode107Binary 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 a binary tree node. * 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) { if (!root) { return vector<vector<int> >(); } vector<vector<int> > vi; queue<TreeNode*> st; st.push(root); int count = 1; vector<int> vti; while (!st.empty()) { TreeNode * tempTreeNode = st.front(); st.pop(); vti.push_back(tempTreeNode->val); if (tempTreeNode->left) { st.push(tempTreeNode->left); } if (tempTreeNode->right) { st.push(tempTreeNode->right); } count--; if (count == 0) { vi.push_back(vti); count = st.size(); vti.clear(); } } return vector<vector<int> >(vi.rbegin(), vi.rend()); }};
0 0
- leetcode刷题,总结,记录,备忘 107
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- 配置JSDoc用conf.json
- PHP开发环境搭建(PHP+Apache+MySQL)
- 关于Deadlock的例子
- EJB杂项
- Map遍历
- leetcode刷题,总结,记录,备忘 107
- LA 3989 - Ladies' Choice【稳定婚姻问题】
- 多个大小不同的UILabel底部对齐的方法
- 排序
- leetcode hIndex implemented with python
- 第二周项目三—体验复杂度(2)
- Scrum Meeting
- 0 基础怎样开始学习做网站 (Ruby on Rails)?
- document 和 window.document