[leetcode刷题系列]Binary Tree Level Order Traversal II
来源:互联网 发布:淘宝客和返利网是什么 编辑:程序博客网 时间:2024/04/28 08:21
练习了一下vector的resize用法- -
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution { vector<vector<int> > vc; void dfs(TreeNode * root, int dep){ if(vc.size() < dep) vc.resize(dep); vc[dep - 1].push_back(root->val); if(root->left != 0) dfs(root->left, dep + 1); if(root->right != 0) dfs(root->right, dep + 1);}public: vector<vector<int> > levelOrderBottom(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function // reset vc.clear(); if(root == 0) return vc; // get the ans dfs(root, 1); reverse(vc.begin(), vc.end()); // ret return vc; }};
- [leetcode刷题系列]Binary Tree Level Order Traversal II
- LeetCode刷题笔录Binary Tree Level Order Traversal II
- 【Leetcode长征系列】Binary Tree Level Order Traversal II
- [leetcode刷题系列]Binary Tree Zigzag Level Order Traversal
- [leetcode刷题系列]Binary Tree Level Order Traversal
- 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
- codeforces 336c
- hdu 2473 Junk-Mail Filter
- 简单多线程
- 字符编码介绍
- Organizing Your Speech
- [leetcode刷题系列]Binary Tree Level Order Traversal II
- ZOJ 3203 Light Bulb【可求出极值的单峰函数】
- Java中堆内存与栈内存分配浅析(重点已做记号)
- Stage Performance
- C#试题
- Java多线程——3 任务的提交者和执行者Executor
- 设计模式之路--综述
- 基于MFC的ActiveX控件开发
- jxl的api--java解析Excel