LeetCode 98. Validate Binary Search Tree (验证二叉搜索树) 题目 链接 https://leetcode.cn/problems/validate-binary-search-tree/ 问题描述 给你一个二叉树的根节点 root ,判断其是否是一个有效的二叉搜索树。 有效 二叉搜索树定义如下: 节点的左子树只包含 小于 当前节点的数
原因:文件中含有控制字符 解决方案: 使用 rz -be -b:–binary 用binary的方式上传下载,不解释字符为ascii; -e:–escape 强制escape 所有控制字符,比如Ctrl+x,DEL等 解压文件: tar -zxvf
LeetCode 700. Search in a Binary Search Tree (二叉搜索树中的搜索) 题目 链接 https://leetcode.cn/problems/search-in-a-binary-search-tree/ 问题描述 给定二叉搜索树(BST)的根节点 root 和一个整数值 val。 你需要在 BST 中找到节点值等于 val 的节点。 返回以该节点为
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 DFS. 对树进行先序遍历,在搜索过程中,总是先访问右子树,根 -> 右 -> 左。那么对于每层来说,在这层见到的第一个结点一定是最右边的结点。 2、代码实现 package Q0199.Q0199BinaryTreeRightSideView; import DataStructure.TreeNod
0. 注意事项与声明 本文摘录整理自 Data Structures, Algorithms, and Applications in C++. 作者: JamesNULLiu 邮箱: jamesnulliu@outlook.com 博客: www.cnblogs.com/jamesnulliu/ 学习笔记 请注明出处 欢迎留言 1. 中英词汇对应表 树 tree 二叉树 binary tree 完全二叉树
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Solution 用 \(queue\) 将元素压入队列,然后每次循环该层的所有
1.二叉树的类定义 2.二叉树的基本性质 3.遍历二叉树 3.1前序遍历 3.2中序遍历 3.3后序遍历 3.4层次遍历 4.二叉树的应用 4.1二叉搜索树 4.2平衡二叉树 4.3红黑树 4.4线段树
字符集是什么: 字符集是指一种从二进制编码到某类字符符号的映射,每一类编码字符都有其对应的字符集和校对规则.每种字符集都可能有多种校对规则,并且都有一个默认的校对规则 校对是什么: “校对”是指一组用于某个字符集的排序规则,对于校对规则通常需要考虑的一个问题是,
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 先序遍历: 根左右,递归实现。 2、代码实现 package Q0199.Q0144BinaryTreePreorderTraversal; import DataStructure.TreeNode; import java.util.ArrayList; import java.util.List; /* 先序遍历: 根左右 method 1:
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 后序遍历,左右根,递归实现。 2、代码实现 package Q0199.Q0145BinaryTreePostorderTraversal; import DataStructure.TreeNode; import java.util.ArrayList; import java.util.List; public class Solution { public Lis
前因: 事情是这样的,前几天不是使用Laravel做了一个图片比对的功能么,因为需要安装Composer扩展,并且这个扩展的使用,需要开启PHP的GD库的扩展支持。 所以本地以及都调试好了,于是今天就上线。然后问题就来了,上线后,请求测试方法,接口直接报 500了。 后果: 因为是线上环境,所以
C. Binary String https://codeforces.ml/contest/1680/problem/C 题意 给你一个01字符串 可以选择再最前面和最后面删除若干个0或1 然后取剩余的0的个数和删去的个数中较大的那个数作为答案 求最小答案 思路 二分 + 双指针 也可以直接双指针 二分答案 首先预处理计算出01串中1的
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
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)\)。当没有左右子节点时
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 递归实现 1> 递归出口。遍历当前结点为空,返回0。 2> 递归分解。当前高度=max{左子树高度,右子树高度} +1。 2、代码实现 package Q0199.Q0104MaximumDepthofBinaryTree; import DataStructure.TreeNode; /* Depth first s
MySQL CRUD 问题描述 mysql在Windows下是不区分大小写的,而Linux下区分大小写,Windows下将script文件导入MySQL后表名也会自动转化为小写,如果导入Linux服务器中使用就会发生错误。 如何在Windows下让它区分大小写呢? 三种方法,任选一种即可 需要设置collate(校对) 这个可以在建表的时
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 使用BFS+递归,逐层遍历树,若当前层level为奇数,头插结点;若当前level为偶数,尾插结点。 2、代码实现 package Q0199.Q0103BinaryTreeZigzagLevelOrderTraversal; import DataStructure.TreeNode; import java.util.ArrayList; imp
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 迭代法,使用队列。 2、代码实现 package Q0199.Q0102BinaryTreeLevelOrderTraversal; import DataStructure.TreeNode; import java.util.LinkedList; import java.util.List; import java.util.Queue; public class Solutio
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 定义两个函数 G(n): 长度为n的序列能构成的不同二叉搜索树的个数。 F(i, n): 以i为根、序列长度为n的不同二叉搜索树个数(1 <= i <= n) G(n) = sum{F(i, n)} i in [1, n] 对于边界情况,当序列长度为1(只有根)或为0(空树): G(0)
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 利用BST的中序遍历为递增序:遍历 1 ~ n,工作变量为i。设genTrees(int start, int end) 为构造树的方法 若i为根结点,则 left =genTrees(1, i - 1); right = genTrees(i + 1, n)。 2、代码实现 package Q0099.Q0095UniqueBinarySea
原题传送门 1. 题目描述 2. Solution 1 1、思路分析 中序遍历:左、根、右。递归实现 2、代码实现 package Q0099.Q0094BinaryTreeInorderTraversal; import DataStructure.TreeNode; import java.util.ArrayList; import java.util.List; public class Solution1 { /*
binary_threshold——用二进制阈值来分割图像。 Halcon算子原型:binary_threshold(Image : Region : Method, LightDark : UsedThreshold)参数:Image:需要进行阈值的图像Region:处理后的区域Method:分割方法('max_separability':最大限度的可分性, 'smooth_histo':直方图平滑)LightDar
每日一题 Day2 题目描述 Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0. 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/binar
原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv/ 题目: Given the root of a binary tree and an array of TreeNode objects nodes, return the lowest common ancestor (LCA) of all the nodes in nodes. All the nodes will
原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/ 题目: Given two nodes of a binary tree p and q, return their lowest common ancestor (LCA). Each node will have a reference to its parent node. The definition for No