binary-tree-maximum-path-sum leetcode maximum

【LeetCode滑动窗口专题#2】无重复字符的最长子串

[#1传送门](https://www.cnblogs.com/DAYceng/p/17263069.html) [滑动窗口最大值](https://www.cnblogs.com/DAYceng/p/17124469.html#%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A ......
字符 LeetCode 专题

LeetCode 2116. 判断一个括号字符串是否有效

````java import java.util.ArrayDeque; import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.u ......
括号 字符串 字符 LeetCode 2116

LeetCode 剑指 Offer 65. 不用加减乘除做加法

````java /** * 写一个函数,求两个整数之和,要求在函数体内不得使用 “+”、“-”、“*”、“/” 四则运算符号。 * * 示例: * 输入: a = 1, b = 1 * 输出: 2 * * 提示: * a, b 均可能是负数或 0 * 结果不会溢出 32 位整数 * * 0000 ......
加减乘除 加法 LeetCode 不用 Offer

LeetCode----前缀和

# 1 算法原理 **适用场景:利用preSum 数组,可以在O(1)的时间内快速求出nums任意区间[i,j]内的所有元素之和** **sum(i,j) = preSum(j + 1) - preSum[i]** ![](https://img2023.cnblogs.com/blog/21670 ......
前缀 LeetCode

LeetCode----回溯

# 1 算法模板 ``` for 选择 in 选择列表: # 做选择 将该选择从选择列表移除 路径.add(选择) backtrack(路径, 选择列表) # 撤销选择 路径.remove(选择) 将该选择再加入选择列表 ``` # 2 代码示例 [46. 全排列](https://leetcode ......
LeetCode

LeetCode----二维网格DFS

# 1 算法模板 ``` void dfs(int[][] grid, int r, int c) { // 判断 base case // 如果坐标 (r, c) 超出了网格范围,直接返回 if (!inArea(grid, r, c)) { return; } // 访问上、下、左、右四个相邻结 ......
网格 LeetCode DFS

[LeetCode] 1351. Count Negative Numbers in a Sorted Matrix

Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid. Exampl ......
LeetCode Negative Numbers Matrix Sorted

递归-二叉搜索树-leetcode98验证二叉搜索树

```java //leetcode submit region begin(Prohibit modification and deletion) /** * Definition for a binary tree node. * public class TreeNode { * int va ......
leetcode 98

LeetCode35.搜索插入位置

//个人学习笔记用 - 题目: 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 请必须使用时间复杂度为 O(log n) 的算法。 参考题解--代码随想录 - 暴力解法: ~~~c++ class Solution { pub ......
LeetCode 位置 35

【每日一题】Problem 1832B - Maximum Sum

[原题](https://codeforces.com/problemset/problem/1832/B) #### 解决思路: 类似滑动窗口的方式,窗口大小为 k 次操作,从中找到更大的结果即可 #### 误区: 一开始的想法是每次都在前一次的基础上减去最少的,然而在样例的第五个测试点出错,因为 ......
Problem Maximum 1832B 1832 Sum

LeetCode 90. 子集 II

``` class Solution { public: unordered_map cnt; vector> res; vector path; vector> subsetsWithDup(vector& nums) { for(auto i:nums) cnt[i]++; dfs(-10);/ ......
子集 LeetCode 90 II

【leetcode】104. Maximum Depth of Binary Tree

给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 **说明:** 叶子节点是指没有子节点的节点。 **示例:** 给定二叉树 `[3,9,20,null,null,15,7]`, ``` 3 / \ 9 20 / \ 15 7 ``` 返回它的最大深度 3 ......
leetcode Maximum Binary Depth Tree

LeetCode 40. 组合总和 II

``` class Solution { public: vector> res; vector> combinationSum2(vector& candidates, int target) { sort(candidates.begin(),candidates.end()); dfs(can ......
总和 LeetCode 40 II

LeetCode 39. 组合总和

``` class Solution { public: vector> res; vector> combinationSum(vector& candidates, int target) { dfs(candidates,0,target); return res; } vector path ......
总和 LeetCode 39

【leetcode】21. Merge Two Sorted Lists

将两个升序链表合并为一个新的 **升序** 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 **示例 1:** ![](https://assets.leetcode.com/uploads/2020/10/03/merge_ex1.jpg) **输入:**l1 = \[1,2,4\] ......
leetcode Sorted Merge Lists Two

Leetcode 2611. 老鼠和奶酪

### 题目: 有两只老鼠和 `n` 块不同类型的奶酪,每块奶酪都只能被其中一只老鼠吃掉。 下标为 `i` 处的奶酪被吃掉的得分为: - 如果第一只老鼠吃掉,则得分为 `reward1[i]` 。 - 如果第二只老鼠吃掉,则得分为 `reward2[i]` 。 给你一个正整数数组 `reward1` ......
奶酪 Leetcode 老鼠 2611

LeetCode----字典树

# 1 原理 [字典树原理参考](https://blog.csdn.net/m0_46202073/article/details/107253959) # 2 构建字典树 ```python class Trie: def __init__(self): # 字典树结构 # children 数 ......
字典 LeetCode

Leetcode刷题指南

## 1. 数据结构 ### 1.1 数组 - **循环数组问题**:把数组扩大为两倍即可,但不是真的扩大两倍,而是通过索引取模的方式 ### 1.2 链表 链表可以通过引入虚拟头节点 `ListNode *dummy = new ListNode{-1, nullptr}` 来极大简化 0. ** ......
Leetcode 指南

leetcode 17. 电话号码的字母组合

## 递归 自己写了个递归的算法 ```java class Solution { public List letterCombinations(String digits) { List resList = recursion(digits); return resList; } public L ......
电话号码 字母 leetcode 号码 电话

Leetcode 2352. 相等行列对

### 题目: 给你一个下标从 `0` 开始、大小为 `n x n` 的整数矩阵 `grid` ,返回满足 `R~i~` 行和 `C~j~` 列相等的行列对 `($$R_i$$, C~j~)` 的数目。 如果行和列以相同的顺序包含相同的元素(即相等的数组),则认为二者是相等的。 ### 难度:简单 ......
行列 Leetcode 2352

leetcode 15. 三数之和

## 暴力法 暴力解法总是最直接能想到的解法。 ```java NA ``` ## 双指针法 贴一个评论区看到的解法 ```java class Solution { //定义三个指针,保证遍历数组中的每一个结果 //画图,解答 public List> threeSum(int[] nums) { ......
之和 leetcode 15

Leetcode Hot 100 & 49. Group Anagrams

写在前面: 不知不觉已经研二下了,既然选择以后走AI这条路,不可避免地也得刷一刷leetcode题目,因为招聘的时候笔试总是要用到的。首先刷一刷leetcode的hot 100题,好记性赶不上烂笔头,记录下来在写这些算法题中的收获给自己看。 参考资料: 考点:哈希 & [题干] 这题没做出来,第一次 ......
Leetcode Anagrams Group Hot 100

[LeetCode] 2352. Equal Row and Column Pairs

Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal. A row and column pair is co ......
LeetCode Column Equal Pairs 2352

[LeetCode] 1347. Minimum Number of Steps to Make Two Strings Anagram 制造字母异位词的最小步骤数

You are given two strings of the same length `s` and `t`. In one step you can choose **any character** of `t` and replace it with **another character* ......
字母 LeetCode 步骤 Anagram Minimum

leetcode-图论总结

此文总结一下常见图论算法,代码可以为后续遇见类似题目提供参考: 1. 图的表示: 邻接矩阵:可通过创建数组得到 邻接表:我个人喜欢通过LinkedList<int[]>[] graph = new LinkedList[n];得到。 Edge List:同样可以通过LinkedList<int[]> ......
leetcode

leetcode-滑动窗口总结

滑动窗口是我在刷题时感觉比较困难的部分,简单做一个总结,防止之后又忘了: 一般模板如下: // 注意:java 代码由 chatGPT🤖 根据我的 cpp 代码翻译,旨在帮助不同背景的读者理解算法逻辑。 // 本代码还未经过力扣测试,仅供参考,如有疑惑,可以参照我写的 cpp 代码对比查看。 /* ......
leetcode

Leetcode 2460. 对数组执行操作

### 题目: 给你一个下标从 **0** 开始的数组 `nums` ,数组大小为 `n` ,且由 **非负** 整数组成。 你需要对数组执行 `n - 1` 步操作,其中第 `i` 步操作(从 **0** 开始计数)要求对 `nums` 中第 `i` 个元素执行下述指令: - 如果 `nums[i ......
数组 Leetcode 2460

[LeetCode] 2460. Apply Operations to an Array

You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith ......
Operations LeetCode Apply Array 2460

LeetCode 669. 修剪二叉搜索树

#### 思路 - 遍历所有节点,如果当前节点不在所给区间里,删除该点;否则 - 如果该点要被删除,将其左右子树其中之一提上来即可 - 根节点位于左右子树取值区间的中间,如果该点要被删除,那么一定存在不满足要求的子树,不可能两棵子树同时保留 #### 代码 ```c class Solution { ......
LeetCode 669

[LeetCode] 1346. Check If N and Its Double Exist 检查整数及其两倍数是否存在

Given an array `arr` of integers, check if there exist two indices `i` and `j` such that : - `i != j` - `0 这道题给了一个整型数组,让检测是否有一个数字和其倍数同时存在的情况。一看到这道题博主就 ......
倍数 整数 LeetCode Double Check