Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in order without duplicate nodes. Left boundary is defined as the path from root to the left-most node. Right boundary is defined ...
The boundary of a binary tree is the concatenation of the root, the left boundary, the leaves ordered from left-to-right, and the reverse order of the right boundary. The left boundary is the set of nodes defined by the following: The root node's left child is in the left boundary. ...
Leetcode 104. Maximum Depth of Binary Tree Leetcode 104. Maximum Depth of Binary Tree 题目描述:找出二叉树的最大深度。 题目链接:Leetcode 104. Maximum Depth of Binary Tree 思路:递归的做法就是不断返回二叉树的左子树右子树深度比较大的那一个。 迭代的做法就是,用hashmap记录每个节点的深度,然后不...
1对boundary理解有误,比如左边的boundary,要是子树中没有左子树,右子树的点也是bounday的;同理右boundary也一样 2 root直接单独处理会简单些
LeetCode 545. Boundary of Binary Tree 原题链接在这里:https://leetcode.com/problems/boundary-of-binary-tree/description/ 题目: Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in ...
vector<int> boundaryOfBinaryTree(TreeNode*root) {if(!root)return{}; vector<int>res, right; TreeNode*l = root->left, *r = root->right, *p =root;if(root->left || root->right) res.push_back(root->val);while(l && (l->left || l->right)) { ...
Given a binary tree,returnthe values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in order without duplicate nodes. Left boundary is defined as the path from root to the left-most node. Right boundary is defined as...