ICode9

精准搜索请尝试: 精确搜索
  • leetcode-0094 二叉树的中序遍历2022-05-26 21:01:25

    /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) {

  • 力扣简111 二叉树的最小深度2022-05-21 21:31:25

    最开始忽略了左子树为空还得计算右子树的叶子节点深度,直接分为左空右空和其他,对于其他认为直接返回0,导致会直接归入其他而报错! 改正后效果也挺一般:     package leetcode01; //给定一个二叉树,找出其最小深度。最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 publ

  • 【力扣 099】606. 根据二叉树创建字符串2022-05-20 22:02:05

    606. 根据二叉树创建字符串 给你二叉树的根节点 root ,请你采用前序遍历的方式,将二叉树转化为一个由括号和整数组成的字符串,返回构造出的字符串。 空节点使用一对空括号对 "()" 表示,转化后需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。   示例 1: 输入:ro

  • 113. 路径总和 II2022-05-19 22:33:56

    113. 路径总和 II   给你二叉树的根节点 root 和一个整数目标和 targetSum ,找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。 叶子节点 是指没有子节点的节点。   示例 1: 输入:root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22输出:[[5,4,11,2],[5,8,

  • 236. 二叉树的最近公共祖先2022-05-19 22:00:07

    236. 二叉树的最近公共祖先 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个节点 p、q,最近公共祖先表示为一个节点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先)。”   示例 1: 给定一

  • 543. 二叉树的直径2022-05-19 21:35:45

    543. 二叉树的直径 给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。   示例 :给定二叉树           1         / \        2   3       / \           4   5  

  • 222. 完全二叉树的节点个数2022-05-19 21:33:04

    222. 完全二叉树的节点个数 给你一棵 完全二叉树 的根节点 root ,求出该树的节点个数。 完全二叉树 的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置。若最底层为第 h 层,则该层包含 1~ 2h 个节点

  • 力扣简101 对称二叉树2022-05-19 11:31:21

    自己先写了一下,还是不会做树! 下面是自己的代码,仍然有问题,甚至考虑这种思路会不会做不出来! package leetcode01; class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, Tr

  • LeetCode(面试题17.12)BiNode2022-05-18 21:34:44

    虽然过了,但是还是不是很清楚,中序遍历,访问每个非空节点时,将左指针置空,pre记录每个父节点,父节点的right置为当前节点 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :

  • 代码随想录-二叉树2022-05-18 20:33:21

    #include <iostream> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <unordered_map> using namespace std; struct TreeNode { int val = 0; TreeNode* left = nullptr; TreeNode*

  • 面试题 04.09. 二叉搜索树序列-----回溯法2022-05-16 23:33:11

    题目表述 从左向右遍历一个数组,通过不断将其中的元素插入树中可以逐步地生成一棵二叉搜索树。 给定一个由不同节点组成的二叉搜索树 root,输出所有可能生成此树的数组。 示例: 输入: root = [2,1,3] **输出: **[[2,1,3],[2,3,1]] **解释: **数组 [2,1,3]、[2,3,1] 均可以通过从左向

  • leetcode 每日一题 面试题 04.06. 后继者2022-05-16 09:31:39

    leetcode 每日一题  面试题 04.06. 后继者 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { boolean b = false;

  • LeetCode 98 Validate Binary Search Tree DFS2022-05-16 06:31:25

    Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nod

  • LeetCode 104 Maximum Depth of Binary Tree DFS2022-05-16 02:01:57

    Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Solution 很基础的 \(DFS\): \(\text{dfs}(root,depth)\)。当没有左右子节点时

  • 05142022-05-15 00:36:28

    101 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {

  • 二叉树——序列化、反序列化2022-05-11 19:02:12

    1. 二叉树的序列化、反序列化 1.1. 问题 将一个二叉树序列化为字符串。 从序列化后的字符串重建一棵二叉树。 1.2. 思路 用#表示空节点,用!表示一个节点的结尾。 这道题可以用二叉树的前序遍历、后序遍历、层序遍历来做。 中序遍历不好做,因为给定一个序列后,没办法一下子将根节点找

  • LeetCode刷题——449. 序列化和反序列化二叉搜索树2022-05-11 15:33:18

    题目描述 序列化是将数据结构或对象转换为一系列位的过程,以便它可以存储在文件或内存缓冲区中,或通过网络连接链路传输,以便稍后在同一个或另一个计算机环境中重建。 设计一个算法来序列化和反序列化 二叉搜索树 。 对序列化/反序列化算法的工作方式没有限制。 您只需确保二叉搜索树

  • LeetCode 0104 Maximum Depth of Binary Tree2022-05-11 09:03:07

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 递归实现 1> 递归出口。遍历当前结点为空,返回0。 2> 递归分解。当前高度=max{左子树高度,右子树高度} +1。 2、代码实现 package Q0199.Q0104MaximumDepthofBinaryTree; import DataStructure.TreeNode; /* Depth first s

  • JZ043往完全二叉树添加节点2022-05-11 00:33:32

    ------------恢复内容开始------------ title: 往完全二叉树添加节点

  • 面试题 04.06. 后继者2022-05-08 21:34:14

    题目表述 设计一个算法,找出二叉搜索树中指定节点的“下一个”节点(也即中序后继)。 如果指定节点没有对应的“下一个”节点,则返回null。 示例 1: 输入: root = [2,1,3], p = 1 2 / 1 3 输出: 2 解题思路 只有两种情况 p没有右子树 p有右子树 如果有右子树的话,那么只需要直接根

  • 剑指Offer-第6天 搜索与回溯算法(简单)2022-05-08 16:35:42

    第一题 题目链接:https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/ 个人题解:BFS即可 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x

  • ztree.js 禁止点击事件和鼠标禁用2022-05-06 17:35:40

    先看样式         var _t = this; var setting = { view: { fontCss: { color: "#5E5F61" }, showIcon: true, showLine: false }, data: { simpleData:

  • LeetCode 113 Path Sum II DFS2022-05-06 03:31:07

    Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references. A root-to-leaf path is a

  • 993. 二叉树的堂兄弟节点(BFS)2022-05-02 02:02:42

    993. 二叉树的堂兄弟节点 在二叉树中,根节点位于深度 0 处,每个深度为 k 的节点的子节点位于深度 k+1 处。 如果二叉树的两个节点深度相同,但 父节点不同 ,则它们是一对堂兄弟节点。 我们给出了具有唯一值的二叉树的根节点 root ,以及树中两个不同节点的值 x 和 y 。

  • 2022-5-1-每日一题-leetcode2022-05-01 09:34:01

    题目链接:https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees/ 个人题解:中序遍历+排序 点击查看代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有