【算法题】102. 二叉树的层序遍历

题目 给你二叉树的根节点 root ,返回其节点值的 层序遍历 。 (即逐层地,从左到右访问所有节点)。 示例 1: 输入:root = [3,9,20,null,null,15,7] 输出:[[3],[9,20],[15,7]] 示例 2: 输入:root = [1] 输出:[[1]] 示例 3: 输入:root = [] 输出:[] 提示: 树中节点数目在范围 [0, 2000] 内 -1000 <...

Leetcode 998. Maximum Binary Tree II (二叉树构建好题)

Maximum Binary Tree II Solved Medium Topics Companies A maximum tree is a tree where every node has a value greater than any other value in its subtree. You are given the root of a maximum binary tree a...

数据结构OJ题——二叉树后序遍历非递归实现(Java版)

题目链接: 二叉树后序非递归遍历实现 前置说明:阅读本文的读者建议先参考我在数据结构专栏里的“二叉树前序、中序遍历非递归实现”这篇博客,因为本文是在那篇博客的基础上延伸的,否则你会觉得我写的是神马玩意@@ 二叉树后序遍历非递归实现 1.1-图文详解1.2-看图说明1.3-完整代码1.4-个人感悟 1.1-图文详解 1.2-看图说明 由于图解很长,为了便于读者阅读,我用一张图说明阅读图解的的顺序。 注:...

Leetcode 1261. Find Elements in a Contaminated Binary Tree (二叉树遍历好题)

Find Elements in a Contaminated Binary Tree Solved Medium Topics Companies Hint Given a binary tree with the following rules: root.val == 0 If treeNode.val == x and treeNode.left != null, then treeNode....

Leetcode 1367. Linked List in Binary Tree (二叉树好题)

[1, 100]. 1 <= Node.val <= 100 for each node in the linked list and binary tree. 解法1: 这题其实并不容易。要在整个二叉树里面,对每个节点调用helper()函数,用前中后序遍历应该都可以。helper()则是用的分解问题的方法。 /** * Definition for singly-linked list. * st...

Leetcode 993. Cousins in Binary Tree (二叉树遍历好题)

Cousins in Binary Tree Easy 3.9K 193 Companies Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the...

【LeetCode:114. 二叉树展开为链表 | 二叉树 + 递归】

🍔 目录 🚩 题目链接⛲ 题目描述🌟 求解思路&实现代码&运行结果⚡ 二叉树 + 递归🥦 求解思路🥦 实现代码🥦 运行结果 💬 共勉 🚩 题目链接 114. 二叉树展开为链表 ⛲ 题目描述 给你二叉树的根结点 root ,请你将它展开为一个单链表: 展开后的单链表应该同样使用 TreeNode ,其中 right 子指针指向链表中下一个结点,而左子指针始终为 null 。 展开后的单链表应该与二叉树 ...

【LeetCode:LCR 143. 子结构判断 | 二叉树 + 递归】

🍔 目录 🚩 题目链接⛲ 题目描述🌟 求解思路&实现代码&运行结果⚡ 二叉树 + 递归🥦 求解思路🥦 实现代码🥦 运行结果 💬 共勉 🚩 题目链接 LCR 143. 子结构判断 ⛲ 题目描述 给定两棵二叉树 tree1 和 tree2,判断 tree2 是否以 tree1 的某个节点为根的子树具有 相同的结构和节点值 。 注意,空树 不会是以 tree1 的某个节点为根的子树具有 相同的结构和节点值 ...

LeetCode二叉树路径和专题:最大路径和与路径总和计数的策略

目录 437. 路径总和 III 深度优先遍历 前缀和优化 124. 二叉树中的最大路径和  437. 路径总和 III 给定一个二叉树的根节点 root ,和一个整数 targetSum ,求该二叉树里节点值之和等于 targetSum 的 路径 的数目。 路径 不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点到子节点)。 示例 1: 输入:root = [10,5,...

Leetcode 1448. Count Good Nodes in Binary Tree (二叉树遍历题)

Count Good Nodes in Binary Tree Medium Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of goo...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.016779(s)
2024-09-17 04:05:36 1726517136