随笔分类 - leetcode_tree
摘要:https://blog.nowcoder.net/n/bb677406ee8e4782badf5fb627e41797 题目分析 题目给出我们一棵树,要求我们实现两个函数 第一个函数要求我们以任意遍历方式返回一个字符串 第二个函数要求我们可以从上一个字符串中重新返回这棵树 方法一:递归 我们采用前
阅读全文
摘要:https://blog.nowcoder.net/n/4fa351e14ee64514babb6742ee023627 题意整理 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。 方法一(递归) 1.解题思路 由于二叉搜索树的中序遍历是从小到大依次输出的,所以可以利用中序遍历,在遍历的
阅读全文
摘要:原文链接:https://blog.csdn.net/weixin_43314519/article/details/107955117 给定一个非空二叉树,返回其最大路径和。 本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。 class
阅读全文
摘要:Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th
阅读全文
摘要:Given a complete binary tree, count the number of nodes. 题目含义:给定一个完整二叉树,求所有节点数 百度百科中完全二叉树的定义如下:若设二叉树的深度为h,除第 h 层外,其它各层 (1~h-1) 的结点数都达到最大个数,第 h 层所有的结点都
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are:
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree [1,null,2,3], return [1,3,2]. 题目含义:用中序遍历树并输出
阅读全文
摘要:Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth
阅读全文
摘要:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: Construct the maximum tree by the given array a
阅读全文
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3
阅读全文
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and
阅读全文
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example:Given the below binary tree and sum
阅读全文
摘要:Given a binary tree, flatten it to a linked list in-place. For example,Given The flattened tree should look like: 方法二:
阅读全文
摘要:Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL
阅读全文
摘要:Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution sti
阅读全文
摘要:You need to find the largest value in each row of a binary tree. Example: 方法二:
阅读全文
摘要:Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [1,2,3]. Note: Recursive solu
阅读全文
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n
阅读全文
摘要:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For exa
阅读全文