• [leetcode-521-Longest Uncommon Subsequence I]

    时间:2024-06-05 21:54:59

    Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defi...

  • LeetCode--11_Container_With_Most_Water

    时间:2024-06-05 08:12:56

    题目链接:点击这里首先我们不考虑高度的话 最大的面积应该是l r 应该是最边上的值 ,我们要取最大 所以 要维护从左到右单调增,从右到左 单调增 这样我们才能保证 面积增加public static int maxArea(int[] height) { int ans = 0; ...

  • Leetcode#150 Evaluate Reverse Polish Notation

    时间:2024-06-04 13:20:33

    原题地址基本栈操作。注意数字有可能是负的。代码: int toInteger(string &s) { int res = ; bool negative = s[] == '-' ? true : false; for (int i = negative ? : ; i &l...

  • leetcode—Populating Next Right Pointers in Each Node

    时间:2024-06-04 09:43:45

    1.题目描述Given a binary tree  struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next...

  • leetcode5 最长回文子串

    时间:2024-06-03 07:21:44

    给你一个字符串 s,找到 s 中最长的 回文 子串。 示例 1: 输入:s = "babad"输出:"bab"解释:"aba" 同样是符合题意的答案。 示例 2: 输入:s = "cbbd"输出:"bb" 思路 以当前字符为中心点,向两边扩展  以当前字符和下一个字符为中心(即回文串长度为偶数) ...

  • 代码随想录——验证二叉搜索树(Leetcode98)

    时间:2024-06-02 22:02:15

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

  • 算法训练营第四十三天 | LeetCode 343 整数拆分、LeetCode 96 不同的二叉搜索树

    时间:2024-06-02 21:00:38

    LeetCode 343 整数拆分 这题其实可以用数学规律:乘积最大时总是分成的数最均衡时取到。 代码如下: class Solution { public int integerBreak(int n) { int[] dp = new int[n + 1]; d...

  • LeetCode42:接雨水

    时间:2024-06-02 12:04:13

    题目描述 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 代码 单调栈 class Solution {public: int trap(vector<int>& height) { stack<in...

  • LeetCode # 608. 树节点

    时间:2024-06-02 08:36:29

    608. 树节点 题目 表:Tree ±------------±-----+ | Column Name | Type | ±------------±-----+ | id | int | | p_id | int | ±------------±-----+ id 是该表中具有唯一值...

  • LeetCode之“动态规划”:Maximum Subarray

    时间:2024-06-02 07:35:46

    题目链接题目要求:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3...

  • LeetCode 图-岛屿问题

    时间:2024-06-01 16:35:56

    图 图的基本知识基本概念图的类型相关术语图的存储LeetCode 相关题目岛屿问题岛屿的最大面积岛屿的周长 图的基本知识 基本概念 图的类型 无向图有向图加权图相关术语 顶点边路径路径长度环负权环连通性顶点的度入度出度图的存储 邻接矩阵存储:是用一个二维数据数组(矩阵)存储图中顶点间的邻接...

  • 每日一题《leetcode--2058. 找出临界点之间的最小和最大距离》

    时间:2024-06-01 10:24:55

    https://leetcode.cn/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/     这道题要求我们求出临界点的最大距离和最小距离。要想求最大和最小距离,首先我们得先求...

  • LeetCode2542最大子序列的分数-解析

    时间:2024-06-01 10:24:35

      这题是给的两个数组,如果是给的组合起来的数据结构就会好理解一点,利用贪心的思维,将影响大的乘法作为先查找的元素,将nums2按从大到小排序(假设nums1和nums2绑定为一个对象,可能比下标排序好理解一点),然后维护一个最小堆去遍历即可。 public long maxScore(int[]...

  • leetcode第33题--Search for a Range

    时间:2024-05-31 09:26:56

    Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord...

  • LeetCode 每日一题 数学篇 2651.计算列车到站时间

    时间:2024-05-30 20:52:25

    给你一个正整数 arrivalTime 表示列车正点到站的时间(单位:小时),另给你一个正整数 delayedTime 表示列车延误的小时数。 返回列车实际到站的时间。 注意,该问题中的时间采用 24 小时制。 int findDelayedArrivalTime(int arrivalTime, ...

  • [LeetCode] Closest Leaf in a Binary Tree 二叉树中最近的叶结点

    时间:2024-05-28 21:34:37

    Given a binary tree where every node has a unique value, and a target key k, find the value of the nearest leaf node to target k in the tree.Here, nea...

  • 【leetcode】623. Add One Row to Tree

    时间:2024-05-28 21:27:37

    题目如下: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 ...

  • Java实现 LeetCode 623 在二叉树中增加一行(遍历树)

    时间:2024-05-28 21:26:21

    623. 在二叉树中增加一行给定一个二叉树,根节点为第1层,深度为 1。在其第 d 层追加一行值为 v 的节点。添加规则:给定一个深度值 d (正整数),针对深度为 d-1 层的每一非空节点 N,为 N 创建两个值为 v 的左子树和右子树。将 N 原先的左子树,连接为新节点 v 的左子树;将 N 原...

  • LeetCode——623.在二叉树中增加一行

    时间:2024-05-28 21:18:44

    给定一个二叉树,根节点为第1层,深度为 1。在其第 d 层追加一行值为 v 的节点。添加规则:给定一个深度值 d (正整数),针对深度为 d-1 层的每一非空节点 N,为 N 创建两个值为 v 的左子树和右子树。将 N 原先的左子树,连接为新节点 v 的左子树;将 N 原先的右子树,连接为新节点 v...

  • Leetcode 623.在二叉树中增加一行

    时间:2024-05-28 21:11:55

    在二叉树中增加一行给定一个二叉树,根节点为第1层,深度为 1。在其第 d 层追加一行值为 v 的节点。添加规则:给定一个深度值 d (正整数),针对深度为 d-1 层的每一非空节点 N,为 N 创建两个值为 v 的左子树和右子树。将 N 原先的左子树,连接为新节点 v 的左子树;将 N 原先的右子树...