leetcode tarjan 341 lca

LeetCode 7023操作使得分最大

# [7023. 操作使得分最大](https://leetcode.cn/problems/apply-operations-to-maximize-score/) 题目描述:一个数字的质数分数为其质因数个数;给定一个长度为$n$的正整数数组`nums`和正整数`k`,可以进行`k`次如下操作: ......
得分 LeetCode 7023

Leetcode No.53 Maximum Subarray

参考资料: 考点:子串 & 动态规划 & [题干] Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6. 1. 心路历程 这道题非常经典, ......
Leetcode Subarray Maximum 53 No

LeetCode 周赛上分之旅 #39 结合中心扩展的单调栈贪心问题

> ⭐️ **本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 \[彭旭锐] 和 [BaguTree Pro](https://www.mdnice.com/writing/85b28c4e60354865a423728e668fc570) 知识星球提问。** > > 学习数据 ......
LeetCode 之旅 问题 39

tarjan模板

```cpp il void tarjan(int u) { dfn[u]=low[u]=++num,st[++top]=u,ins[u]=1; G(i,u) { int v=ver[i]; if(!dfn[v]) { tarjan(v); low[u]=min(low[u],low[v]); } ......
模板 tarjan

LeetCode 7022——熟悉TreeSet数据结构及常用方法的使用

LeetCode 7022. 限制条件下元素之间的最小绝对差 题目描述: 给你一个下标从 0 开始的整数数组 nums 和一个整数 x 。 请你找到数组中下标距离至少为 x 的两个元素的 差值绝对值 的 最小值 。 换言之,请你找到两个下标 i 和 j ,满足 abs(i - j) >= x 且 a ......
数据结构 LeetCode 常用 TreeSet 结构

C++STL库 二分查找,以及对set集合进行二分查找,来源于”leetcode7022. 限制条件下元素之间的最小绝对差“

C++的头文件<algorithm>中有用于二分查找的函数,lower_bound()、upper_bound()以及binary_search(): lower_bound():返回大于等于目标值的第一个位置upper_bound():返回大于目标值的第一个位置,binary_search():若 ......
leetcode 元素 条件 之间 来源

Leetcode 209. 长度最小的子数组(Minimum size subarray sum)

[题目链接](https://leetcode.cn/problems/minimum-size-subarray-sum) 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, ..., ......
数组 长度 Leetcode subarray Minimum

LeetCode--1039

Smiling & Weeping 我总是躲在梦与季节的身处, 听花与黑夜唱尽梦魇, 唱尽繁华,唱断所有记忆的来路。 题目链接:1039. 多边形三角剖分的最低得分 - 力扣(LeetCode) 题目描述: 你有一个凸的 n 边形,其每个顶点都有一个整数值。给定一个整数数组 values ,其中 v ......
LeetCode 1039

【图论】最近公共祖先(LCA)

## 什么是LCA 最近公共祖先是相对于两个节点来说的,顾名思义,最近公共祖先即为两个节点公共的最近的祖先。 ![image](https://img2023.cnblogs.com/blog/3257810/202308/3257810-20230812133415742-926455766.pn ......
祖先 LCA

Tarjan 例题:洛谷P4819 [中山市选] 杀人游戏

### [在洛谷中查看](https://www.luogu.com.cn/problem/P4819) ### 前言: 这道题挺好,有很多坑点,锻炼思维,和 Codeforces 的思维题有些相似。 ### 思路: #### 第一阶段: 很明显,在一个强连通分量里的点都能知道别人是不是杀手。那么就 ......
例题 Tarjan P4819 4819

Leetcode 977. 有序数组的平方(Squares of a sorted array)

[题目链接](https://leetcode.cn/problems/squares-of-a-sorted-array) 给你一个按**非递减顺序**排序的整数数组nums, 返回每个数字的平方组成的新数组, 要求也按**非递减顺序**排序. 示例 1: ``` 输入:nums = [-4,-1 ......
数组 Leetcode Squares sorted array

Tarjan 例题:洛谷P1407 [国家集训队] 稳定婚姻

### [在洛谷中查看](https://www.luogu.com.cn/problem/P1407) ### 题意: 自己读一下,大致就是 $2n$ 个点,每个点编号为 $1 - 2n$,$\lfloor 编号/2 \rfloor$ 相同的点连条边。 然后再给 $m$ 条边。 问:将每个 $\l ......
集训队 例题 婚姻 国家 Tarjan

Leetcode 27. 移除元素(Remove Element)

[题目链接](https://leetcode.cn/problems/remove-element) 给你一个数组nums和一个值val, 你需要**原地**移除所有数值等于val的元素, 并返回移除后数组的新长度. 不要使用额外的数组空间, 你必须仅使用O(1)额外空间并**原地**修改输入数组 ......
Leetcode 元素 Element Remove 27

题解 Gym 102978F【Find the LCA】

## problem You are given an integer sequence $A_1,A_2,\ldots,A_N$. You'll make a rooted tree with $N$ vertices numbered from $1$ through $N$. The vert ......
题解 102978F 102978 Find Gym

Leetcode167. 两数之和 II - 输入有序数组(双指针)

题目: [ 两数之和 II - 输入有序数组(双指针)](https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/description/) 给你一个下标从 1 开始的整数数组 numbers ,该数组已按 非递减顺序排列 ,请你从 ......
之和 数组 指针 Leetcode 167

LeetCode -- 827. 最大人工岛

题目大意:给一个邻接矩阵,问改变一个点后,最大连通块多大 对于这种连通块相关问题,一般的思路就是进行深搜和并查集,这里采用并查集维护连通块大小解法。 首先先初始化并查集,并进行连通块的合并;再对图中的0进行枚举,找到最大的连通块即可。 对(n * m)的二维点阵图常用技巧,二维转一维:点(i, j) ......
人工岛 人工 LeetCode 827

LeetCode从算法到算命—1281.整数的各位积和之差(20230809)

# 1281.整数的各位积和之差 ## 题目信息 给你一个整数 `n`,请你帮忙计算并返回该整数「各位数字之积」与「各位数字之和」的差。 **示例 1:** ``` 输入:n = 234 输出:15 解释: 各位数之积 = 2 * 3 * 4 = 24 各位数之和 = 2 + 3 + 4 = 9 结 ......
整数 算法 LeetCode 20230809 1281

Tarjan例题:洛谷 P2863 [USACO06JAN] The Cow Prom S

### [在洛谷中查看](https://www.luogu.com.cn/problem/P2863) 模板题,缩完点后扫一遍就行了。 巩固基础。 ```cpp #include using namespace std; const int N = 1e4+5; int n,m,dfn[N],lo ......
例题 Tarjan P2863 USACO 2863

有效的括号--LeetCode算法

不用map的解法 public boolean isValid(String s) { //输入的字符串为空,直接返回true if(s.isEmpty()) return true; //新建一个栈 Stack<Character> stack=new Stack<Character>(); // ......
括号 算法 LeetCode

Leetcode 704. 二分查找(Binary Search)

[题目链接](https://leetcode.cn/problems/binary-search) 给定一个n个元素有序的(升序)整型数组`nums`和一个目标值`target`, 写一个函数搜索`nums`中的`target`, 如果目标值存在返回下标, 否则返回`-1`。 示例 1: ``` ......
Leetcode Binary Search 704

LeetCode从算法到算命—1749.任意子数组和的绝对值的最大值

# 1749.任意子数组和的绝对值的最大值 ## 题目信息 给你一个整数数组 `nums` 。一个子数组 `[numsl, numsl+1, ..., numsr-1, numsr]` 的 **和的绝对值** 为 `abs(numsl + numsl+1 + ... + numsr-1 + nums ......
绝对值 最大值 数组 算法 LeetCode

使用golang解决LeetCode热题Hot100(1-10)

# 使用golang解决LeetCode热题Hot100 ## 1.两数之和 ### https://leetcode.cn/problems/two-sum/ #### 题目 给定一个整数数组 `nums` 和一个整数目标值 `target`,请你在该数组中找出 **和为目标值** *`targe ......
LeetCode golang Hot 100 10

Leetcode刷题记录本

# Leetcode刷题记录本 ### ID: 1 点击查看代码 1. 暴力破解法 ```python class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: in ......
Leetcode

leetcode:下一个排列

class Solution { public: void nextPermutation(vector<int>& nums) { int n=nums.size(); int i=n-2; while(i>=0 && nums[i]>=nums[i+1]){//从后向前,找到第一个降序的,一直升 ......
leetcode

LeetCode -- 127. 单词接龙

方法一:双向广搜 class Solution { public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { set<string> se; for(auto it : wordLis ......
接龙 单词 LeetCode 127

LeetCode 热题 100 之 240. 搜索二维矩阵 II

# 题目 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target 。该矩阵具有以下特性: 每行的元素从左到右升序排列。 每列的元素从上到下升序排列。 **示例一** ![image](https://img2023.cnblogs.com/blog/2204134/2 ......
矩阵 LeetCode 100 240 II

Tarjan

我写这个随笔是让我更加理解算法,防止以后出错,因为我今天调Tarjan调了3个多小时,后来还是在大佬的帮忙下调出来了,问题不少 先来看错误的(40pts): //缩点 //https://www.luogu.com.cn/problem/P3387 #include<bits/stdc++.h> # ......
Tarjan

LeetCode 16. 3Sum Closest 双指针+排序

Given an integer array `nums` of length n and an integer `target`, find three integers in nums such that the sum is closest to `target`. Return the su ......
指针 LeetCode Closest 3Sum Sum

LCA(菜鸟笔记)

**LCA**就是求树上两个节点的最近的公共祖先。 我们定义一个节点的祖先是这个节点向根节点走时所经过的所有节点并且包括该节点本身。 ### LCA(暴力) 介绍一下**比较暴力**的求两个节点的LCA。 我们现在有两个节点 $u$ 和 $v$,求它们的LCA。我们从 $u$ 出发一直走到根节点,期 ......
笔记 LCA

tarjan全家桶

### 割边 对于一个无向图,如果删掉一条边后图中的连通分量数增加了,则称这条边为桥或者割边。严谨来说,就是:假设有连通图 $G=\{V,E\}$,e 是其中一条边(即 $e \in E$),如果 $G-e$ 是不连通的,则边 $e$ 是图 $G$ 的一条割边(桥)。 ### 割边判定法则 无向边 ......
全家 tarjan