ICode9

精准搜索请尝试: 精确搜索
  • 力扣练习——44 路径总和 III2022-07-28 11:35:56

    1.问题描述 给定一个二叉树,它的每个结点都存放着一个整数值。 找出路径和等于给定数值的路径总数。 路径不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点到子节点)。 二叉树不超过1000个节点,且节点数值范围是 [-1000000,1000000] 的整数。   示例:

  • LeetCode 103 Binary Tree Zigzag Level Order Traversal 双端队列 Deque2022-07-28 04:33:41

    Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between). Solution 由于是 \(zigzag\) 的形式,刚开始的思路是用 \(stack\) 来维护反序,但是

  • 力扣 题目99- 验证二叉搜索树2022-07-27 19:35:28

    题目 题解 在力扣 题目98- 验证二叉搜索树中 我们知道了 中序遍历后的二叉搜索树 应该为递增 那么出错就应该是有部分递减 那么我们在98题的基础上 反向检测 保存减少数列的开头与结尾进行交换 代码 1 #include<iostream> 2 #include<vector> 3 #include<stack> 4 using n

  • [LeetCode] 919. Complete Binary Tree Inserter2022-07-26 01:32:00

    A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. Design an algorithm to insert a new node to a complete binary tree keeping it complete after the inser

  • LeetCode 102 Binary Tree Level Order Traversal 层序BFS2022-07-24 06:00:14

    Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). Solution 用 \(BFS\) 即可,每次将该层的节点 \(pop\), 然后 \(push\) 其子数的节点 点击查看代码 /** * Definition for a binary tree n

  • 【算法学习】递归篇2022-07-23 15:04:55

    【2022/7/21】814. 二叉树剪枝 问题 知识点回顾 1. 什么是二叉树? 本身是有序树 树中包含的各个节点的度不能超过 2,即只能是 0、1 或者 2 2. 二叉树的性质 第 i 层最多有 2i-1 个结点 若二叉树的深度为 K,那么此二叉树最多有 2K-1 个结点 解题思路 用递归实现: 临界值:当传入的

  • [LC814]二叉树剪枝2022-07-22 00:37:35

    题目 题目地址 分析 这道题符合递归的性质,对于当前的节点node,当且仅当其左右孩子都为不包含1的子树,且node.val=1时,node所在的子树才符合“不包含1的子树”这一定义。那么很自然的,我们可以采取树的后序处理,递归的处理上述条件,具体代码如下。 代码 Golang代码 /* * @lc app=leetc

  • 算法:对称的二叉树2022-07-21 23:00:26

    问题 请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 解决 //定义二叉树结构 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * Tr

  • ztree树 metro风格 鼠标经过 显示用户自定义控件 新增,编辑,删除,向下,向上操作2022-07-21 15:01:44

    <!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - Simple Data</TITLE> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="z

  • 力扣 题目95- 不同的二叉搜索树 II2022-07-19 18:34:51

    题目 题解 我们可以将一个大的二叉搜索树分成越来越小的二叉搜索树  那么问题是如何取左节点 与 右节点的可能性 也就是我们需要的做 便是如何找到左节点范围 右节点范围 二叉搜索树 //左节点比根节点小//右节点比根节点大 //右节点下的子节点也比左节点的子节点大 //已经取过

  • LeetCode 226 Invert Binary Tree DFS2022-07-19 04:31:07

    Given the root of a binary tree, invert the tree, and return its root. Solution: 直接使用 \(DFS\) 进行递归即可: 点击查看代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * T

  • [Google] LeetCode 366 Find Leaves of Binary Tree 思维+DFS2022-07-19 03:02:40

    Given the root of a binary tree, collect a tree's nodes as if you were doing this: Collect all the leaf nodes. Remove all the leaf nodes. Repeat until the tree is empty. Solution 给定一个二叉树,每次输出叶子节点,然后去除叶子节点,不断重复直到根节点也被删除。这道

  • 力扣 题目94- 二叉树的中序遍历2022-07-18 18:05:47

    题目 题解 二叉树有点忘记了 专门去复习了 一遍 其实就是 左中右 一看用递归或者栈吧 栈比较简单一些 我们直接不断向左移动 碰到空就向栈顶的右走即可 代码 1 #include<iostream> 2 #include<vector> 3 #include<stack> 4 using namespace std; 5 6 struct TreeNode {

  • LeeCode 二叉树问题(二)2022-07-15 22:33:58

    二叉树的构建 LeeCode 106: 从中序遍历与后续遍历序列构造二叉树 题目描述 给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。 建立模型 中序遍历和后续遍历数组可以唯一确定二叉树。 中序

  • leetcode.404. 左叶子之和2022-07-15 20:31:16

            输入: root = [3,9,20,null,null,15,7] 输出: 24 解释: 在这个二叉树中,有两个左叶子,分别是 9 和 15,所以返回 24示例 2: 输入: root = [1]输出: 0  提示: 节点数在 [1, 1000] 范围内-1000 <= Node.val <= 1000         /**  * Definition for a binary

  • 剑指 Offer 37. 序列化二叉树2022-07-14 17:36:39

    请实现两个函数,分别用来序列化和反序列化二叉树。你需要设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。提示:输入输出格式与 LeetCode 目前使用

  • 剑指 Offer 34. 二叉树中和为某一值的路径2022-07-13 17:37:13

    给你二叉树的根节点 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,4,5]]示例 2:    

  • 剑指 Offer 28. 对称的二叉树2022-07-10 22:00:52

    请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。例如,二叉树 [1,2,2,3,4,4,3] 是对称的。    1   / \  2   2 / \ / \3  4 4  3但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:    1   / \  2   2   \ 

  • 【力扣 007】107. 二叉树的层序遍历 II2022-07-06 22:03:20

    102. 二叉树的层序遍历 方法1: /** * 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(nullpt

  • 236. 二叉树的最近公共祖先_2022-07-02 21:33:50

    目录236. 二叉树的最近公共祖先思路:代码:总结: 236. 二叉树的最近公共祖先 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个节点 p、q,最近公共祖先表示为一个节点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个

  • 2022-7-2 剑指offer-二叉树-层序遍历变种2022-07-02 12:35:35

    剑指 Offer 32 - III. 从上到下打印二叉树 III 难度中等235收藏分享切换为英文接收动态反馈 请实现一个函数按照之字形顺序打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右到左的顺序打印,第三行再按照从左到右的顺序打印,其他行以此类推。 1 /** 2 * Definition

  • LeetCode面试题 04.06. 后继者2022-07-01 19:01:40

    LeetCode面试题 04.06. 后继者 求中序遍历中给定节点的后一个节点,分右子树中/父节点中 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution:

  • 二叉树的最近公共祖先2022-07-01 16:07:31

          https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/solution/236-er-cha-shu-de-zui-jin-gong-gong-zu-xian-hou-xu/     /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode *

  • 层序建立二叉树并输出,先序遍历二叉树并输出2022-07-01 16:02:47

    func main() { //按数组层序建立二叉树,之后层序输出二叉树 root:=createTree(0,[]int{1,2,3,4,5,6}) ans:=printTree(root) fmt.Println(ans) //先序建立二叉树,之后先序输出二叉树 var tmp *TreeNode for i:=0;i<6;i++{ tmp=insert(tmp

  • 路径总和II2022-06-29 22:00:48

       https://leetcode.cn/problems/path-sum-ii/ /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func pathSum(root *TreeNode, targetSum int) [][]int { stack:=make([]

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

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

ICode9版权所有