Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 2 / 3 return [1,...
Invert a binary tree. 4 / 2 7 / / 1 3 6 9to 4 / 7 2 / / 9 6 3 1Trivia:This problem was inspired by...
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / 2 3 5 All root-to-leaf paths are:["1-...
题目:Binay Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nod
题目:Binary Tree Preorder Traversal二叉树的前序遍历,同样使用栈来解,代码如下: 1 struct TreeNode { 2 int val; 3 TreeNode* left; 4 TreeNode* right; 5......
题目:Binary Tree Inorder Traversal二叉树的中序遍历,和前序、中序一样的处理方式,代码见下: 1 struct TreeNode { 2 int val; 3 TreeNode* left; 4 TreeNode* righ......
该文讲述了如何检测并删除树中冗余的边,以保证树的连通性。首先介绍了并查集,用于检查节点是否属于同一个连通块;然后讲述了如何通过并查集检测冗余边,并返回最后出现在2D数组中的边,保证至少存在一条有效边。...
该文介绍了如何通过递归思想,使用一个递归函数构建一棵树,并利用一个数组来记录每个节点的值。在遍历树的过程中,每当遍历到一个节点时,都会将它的值写入数组中。最后,将数组转换为字符串,即可得到一棵完整的二叉树。...