650. Find Leaves of Binary Tree
class Solution {
public:
vector<vector<int>> findLeaves(TreeNode* root) {
vector<vector<int>> res;
while (root) {
vector<int> leaves;
root = remove(root, leaves);
res.push_back(leaves);
}
return res;
}
TreeNode* remove(TreeNode* node, vector<int>& leaves) {
if (!node) return NULL;
if (!node->left && !node->right) {
leaves.push_back(node->val);
return NULL;
}
node->left = remove(node->left, leaves);
node->right = remove(node->right, leaves);
return node;
}
};
650. Find Leaves of Binary Tree的更多相关文章
- [LeetCode] Find Leaves of Binary Tree 找二叉树的叶节点
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...
- Leetcode: Find Leaves of Binary Tree
Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves ...
- 366. Find Leaves of Binary Tree
Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves ...
- Find Leaves of Binary Tree
Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves ...
- 366. Find Leaves of Binary Tree C#
Example:Given binary tree 1 / \ 2 3 / \ 4 5 Returns [4, 5, 3], [2], [1]. Explanation: 1. Removing th ...
- 366. Find Leaves of Binary Tree输出层数相同的叶子节点
[抄题]: Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all ...
- [leetcode]366. Find Leaves of Binary Tree捡树叶
Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves ...
- LeetCode 366. Find Leaves of Binary Tree
原题链接在这里:https://leetcode.com/problems/find-leaves-of-binary-tree/#/description 题目: Given a binary tr ...
- [LeetCode] 366. Find Leaves of Binary Tree 找二叉树的叶节点
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...
随机推荐
- scala快速入门之文档注释
scala快速入门之文档注释 1.在项目栏的目录树中找到该源码,右击点击Show in Explorer, 即可找到该源码的本地路径,在路径中输入cmd 2.执行scaladoc -d 生成文档注释 ...
- Java httpclent请求httpclentUtils工具类
第一种写法: import java.io.IOException; import java.io.InterruptedIOException; import java.io.Unsupported ...
- sparkstreaming写入hbase表中总结
执行spark代码插入数据到hbase表中去的时候,遇到的错误 1. 缺少hadoop-mapreduce-client-core-2.5.1.jar包 错误:java.lang.ClassNotFo ...
- js--获取和设置css属性
在这一章我们讲述一下如何通过js来操作css中的属性 1,首先,我们想获取元素的一些属性.例如innerHTML,value等值时,我们可以 var object=document.getELemen ...
- python-uiautomator2
简单介绍 python-uiautomator2是一个自动化测试开源工具,仅支持Android平台的原生应用测试. 支持平台及语言 python-uiautomator2封装了谷歌自带的uiautom ...
- Spring Cloud 之 Hystrix 知识点:隔离、熔断、降级
Hystrix 是隔离.熔断以及降级的一个框架. Hystrix 的隔离: Hystrix 会搞很多个小小的线程池,比如订单服务请求库存服务是一个线程池,请求仓储服务是一个线程池,请求积分服务是一个线 ...
- Day01~15 - Python语言基础
Day01 - 初识Python Python简介 - Python的历史 / Python的优缺点 / Python的应用领域 搭建编程环境 - Windows环境 / Linux环境 / MacO ...
- 如何获取gitee上的项目?
对于没有使用过github/gitee的朋友来说,估计是有点懵. 下面举个例子,比如获取我的gitee上的python接口自动化测试框架 访问主页:https://gitee.com/uncleyon ...
- js生成随机密码,密码位数自定
话不多说,上代码 function pb(size){ var seed = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N', ...
- 例程使用(1-4)共享内存 存图片+vector容器教程
1传输的数据 1-1数据格式说明 1 两路视频图像Mat 图像 图像数据(Mat)+图像头信息(ImgInf) //图像的宽.高.类型信息 typedef struct { int width; // ...