650. Find Leaves of Binary Tree
Posted ymjyqsx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
366. Find Leaves of Binary Tree
366. Find Leaves of Binary Tree
Leetcode: Find Leaves of Binary Tree