leetcode tarjan 341 lca

LeetCode[42]TrappingRainWater

# Content Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raini ......
TrappingRainWater LeetCode 42

LeetCode[53]MaximumSubarray

# Content Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Ou ......
MaximumSubarray LeetCode 53

LeetCode[62]UniquePaths

# Content There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the ......
UniquePaths LeetCode 62

LeetCode[55]JumpGame

# Content You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your ......
LeetCode JumpGame 55

LeetCode[64]MinimumPathSum

# Content Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along ......
MinimumPathSum LeetCode 64

[Tarjan] 学习笔记

# 原理 ## 强连通分量 [讲得超级屌,这次比董晓好得多](https://www.bilibili.com/video/BV19J411J7AZ?p=1 "视频") ``` void tarjan(int x) { dfn[x] = low[x] = t ++; s.push(x); in[x] ......
笔记 Tarjan

【LeetCode1270. 向公司CEO汇报工作的所有人】with recursive找到某节点所有的后代

# 题目地址 https://leetcode.cn/problems/all-people-report-to-the-given-manager/description/ # 代码 ``` WITH RECURSIVE cte_subordinates AS ( -- 基础情况: 找到直接下属 ......
节点 后代 recursive LeetCode 所有人

【leetcode】1.two sum

第一题给我干懵了...想达到这个要求把我脑壳都想痛了...Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity? 一开始想过用map,但是不能解决重复key的问题。 然而我用sort, ......
leetcode two sum

【算法学习笔记】DFN序求LCA(最近公共祖先)

## 前置知识 * DFN序:对一棵树进行深度优先搜索`DFS`得到的**结点序列**,即深度优先搜索`DFS`的访问顺序。该表述不一定严谨,建议百度 * ST表(Sparse Table,稀疏表) ## 算法概述 > ###引理 1.1 > 在 DFN序 中祖先一定出现后代之前。 考虑一树上的两个 ......
祖先 算法 笔记 DFN LCA

Tarjan学习笔记

# Tarjan Tarjan算法是图论中非常常用的算法之一,能解决**强连通分量,双连通分量,割点和桥,求最近公共祖先(LCA)**等问题。 > Tarjan 算法是基于深度优先搜索的算法,用于求解图的连通性问题。 ## 割点 如果从图中删除节点 $x$ 以及所有与 $x$ 关联的边之后,图将被分 ......
笔记 Tarjan

LeetCode 1581. 进店却未进行过交易的顾客

##题目 表:Visits ```sql + + + | Column Name | Type | + + + | visit_id | int | | customer_id | int | + + + visit_id 是该表中具有唯一值的列。 该表包含有关光临过购物中心的顾客的信息。 ``` ......
LeetCode 顾客 1581

Leetcode 19. 删除链表的倒数第N个结点(Remove nth node from end of list)

[题目链接](https://leetcode.cn/problems/remove-nth-node-from-end-of-list) 给你一个链表, 删除链表的倒数第n个结点, 并且返回链表的头结点. 示例 1: ``` 输入:head = [1,2,3,4,5], n = 2 输出:[1,2 ......
结点 Leetcode Remove node from

强连通分量与tarjan算法

- # **强连通分量** **强连通**:若一张有向图的节点两两之间可以互相抵达,那么这一张图是强连通的。 **强连通分量**:极大的强连通子图。 对图**深度搜索**的时候,每一个节点只访问一次,被访问过的节点与边构成**搜索树**。 有向边按照**访问的情况**可以分为如下4类: **1. 树 ......
分量 算法 tarjan

【W的AC企划 - 第八期】tarjan缩点

# 往期浏览 [第一期 - 博弈论(game)](https://www.cnblogs.com/WIDA/p/16570498.html) [第二期 - 前缀和](https://www.cnblogs.com/WIDA/p/15504413.html) [第三期 - 二分算法](暂时未公开) [ ......
tarjan

Leetcode148 排序链表

148. 排序链表 - 力扣(LeetCode) /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr ......
Leetcode 148

LeetCode -- 151. 反转字符串中的单词(手写一个trim函数)

本题我们采用 class Solution { public: string reverseWords(string s) { stack<string> stk; int n = s.size(), l = 0, r = n - 1; //trim函数 while(l < n && s[l] == ......
字符串 单词 函数 字符 LeetCode

第 358 场周赛 - 力扣(LeetCode)

# [第 358 场周赛 - 力扣(LeetCode)](https://leetcode.cn/contest/weekly-contest-358/) ## [2815. 数组中的最大数对和 - 力扣(LeetCode)](https://leetcode.cn/problems/max-pai ......
LeetCode 358

【leetcode】404 左叶子之和

https://leetcode.cn/problems/sum-of-left-leaves/description/ 【分析】 该题要求左叶子之和。 如果我们对当前节点进行叶子节点的判断,那么我们是不知道当前节点是左叶子还是右叶子的。 所以我们应该在叶子结点的上层(父节点)进行判断。 【代码】 ......
之和 leetcode 叶子 404

[LeetCode] 2682. Find the Losers of the Circular Game

There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, movin ......
the LeetCode Circular Losers 2682

LeetCode -- 19. 删除链表的倒数第 N 个结点

一般的删除问题,可以直接删除(找符合条件的,找到了直接删掉),延迟删除(打标记,找完了再删除),栈,双指针 在链表中删除一个节点,要找到其前面一个节点cur, 然后 cur -> next = cur -> next -> next即可 方法一:直接删除 我们先算出链表长度len,要删除倒第n个节点 ......
结点 LeetCode 19

【LeetCode 571. 给定数字的频率查询中位数】WITH RECURSIVE实现Tally的逆操作

[TOC] # 题目地址 https://leetcode.cn/problems/find-median-given-frequency-of-numbers/description/ # 代码 ``` WITH RECURSIVE RecCTE AS ( SELECT num, frequenc ......
中位数 RECURSIVE 频率 LeetCode 数字

【leetcode】【401】二进制手表

https://leetcode.cn/problems/binary-watch/description/ 分析 这是典型的循环DFS问题。 循环DFS一般应用在: 1. 输出字符的按位全排列。(比如一共4个数字,输出3个数字的全部组合) 2. 输出字符的全排列。(结合visited数组) 3. ......
二进制 手表 leetcode 401

【LeetCode2308. 按性别排列表格】MySQL实现自定义排序

[TOC] # 题目地址 https://leetcode.cn/problems/arrange-table-by-gender/description/ # 题目描述 编写一个解决方案以重新排列 Genders 表,使行按顺序在 'female', 'other' 和 'male' 之间交替。同 ......
表格 LeetCode 性别 MySQL 2308

P3629 巡逻 LCA题解

原题:[洛谷P3629](https://www.luogu.com.cn/problem/P3629) ## 问题转化 首先,给定的图是一个有 $n$ 个点,$n-1$ 条边的无向连通图,这个图就等价于一棵树。 不建立新的道路时,从 $1$ 号节点出发,把整棵树上的每条边遍历至少一次,再回到 $1 ......
题解 P3629 3629 LCA

LeetCode -- 833. 字符串中的查找与替换 (延迟改变策略)

所谓延迟改变,可以是在应该改变的地方打一个标记,等把所有应该改变的地方都找到后,再进行操作。 class Solution { public: string findReplaceString(string s, vector<int>& indices, vector<string>& sourc ......
字符串 字符 LeetCode 策略 833

Leetcode 206. 反转链表(Reverse linked list)

[题目链接](https://leetcode.cn/problems/reverse-linked-list) 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 示例 1: ``` 输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1] ``` 示例 2: `` ......
Leetcode Reverse linked list 206

P3629 巡逻 LCA题解

原题:[洛谷P3629](https://www.luogu.com.cn/problem/P3629) ## 问题转化 首先,给定的图是一个有 $n$ 个点,$n-1$ 条边的无向连通图,这个图就等价于一棵树。 不建立新的道路时,从 $1$ 号节点出发,把整棵树上的每条边遍历至少一次,再回到 $1 ......
题解 P3629 3629 LCA

[YsOI2023] 广度优先遍历 逆向输出路径(分层建树拓扑序. LCA)

今天的模板测试是无向图上的广度优先遍历,【数据删除】马上写好了代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #includ ......
拓扑 广度 建树 路径 YsOI

[LeetCode] 2369. Check if There is a Valid Partition For The Array

You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays. We call a partition of the array  ......
Partition LeetCode Check Array There

Leetcode 203. 移除链表元素(Remove linked list elements)

[题目链接](https://leetcode.cn/problems/remove-linked-list-elements) 给你一个链表的头节点head和一个整数val , 请你删除链表中所有满足Node.val == val的节点, 并返回新的头节点. 示例 1: ``` 输入:head = ......
Leetcode elements 元素 Remove linked