leetcode tarjan 341 lca

leetcode动态规划题目总结

ref :https://leetcode.cn/circle/article/2Xxlw3/ 这是一篇我在leetcode.com上撰写的文章Dynamic Programming Summary,就不翻回中文了,直接copy过来了。 Hello everyone, I am a Chinese ......
leetcode 题目 动态

动态规划leetcode 清单

不同的二叉搜索树 (卡特兰数) N 天后的牢房 骑士拨号器 最大为 N 的数字组合 鸡蛋掉落 石子游戏 新21点 分汤 有效的井字游戏 统计不同回文子字符串 编辑距离 买卖股票的最佳时机含手续费 爬楼梯 奇怪的打印机 不同路径 II 不同路径 出界的路径数 二叉树的直径 最大子序和 优美的排列 零钱 ......
清单 leetcode 动态

[LeetCode] 1493. Longest Subarray of 1's After Deleting One Element

Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1's in the resulti ......
LeetCode Deleting Subarray Element Longest

动态规划-背包问题-完全背包问题:leetcode 377. 组合总和 Ⅳ

1. 题目 读题 给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target 。请你从 nums 中找出并返回总和为 target 的元素组合的个数。 题目数据保证答案符合 32 位整数范围。 示例 1: 输入:nums = [1,2,3], target = 4输出:7解释:所有可 ......
背包 问题 总和 leetcode 动态

7-010-(LeetCode- 518) 零钱兑换II

1. 题目 读题 518. 零钱兑换 II给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带符号整数。 ......
零钱 LeetCode 010 518

LeetCode C++:HashTable篇

1、Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume tha ......
HashTable LeetCode

leetcode 21. 合并两个有序链表

## 直接合并即可 这道题是简单题,直接合并即可 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int ......
leetcode 两个 21

[LeetCode] 1071. Greatest Common Divisor of Strings

For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times). Given two string ......
LeetCode Greatest Divisor Strings Common

[LeetCode] 1186. Maximum Subarray Sum with One Deletion

Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, y ......
LeetCode Deletion Subarray Maximum 1186

[LeetCode] 2462. Total Cost to Hire K Workers

You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. W ......
LeetCode Workers Total 2462 Cost

LeetCode —— 滑动窗口

904. 水果成篮 用一个 Map 记录当前窗口的情况: key - 水果种类数 value - 这个水果种类在当前滑动窗口里出现的次数 维持一个 left 指针到 right 指针的滑动窗口 每次 right 右移一位,将新加入窗口的 fruits[right] 这个种类放到 map 里,并将该种 ......
LeetCode

[LeetCode] 2485. Find the Pivot Integer

Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements bet ......
LeetCode Integer Pivot 2485 Find

LeetCode 128. 最长连续序列

* 为什么这题我都不会,脑袋有点累,状态真差 ``` class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(),nums.end());//记录数字是否出现过 int re ......
序列 LeetCode 128

leetcode-前缀和数组&差分数组

前缀和数组: 前缀和技巧适用于快速、频繁地计算一个索引区间内的元素之和。(仅仅适用于原数组不变的情况,如果原数组经常修改,则需要考虑差分数组。) 看两道例题就清楚了: 1. 303. 区域和检索 - 数组不可变 - 力扣(LeetCode) 由于要频繁计算某个区间内的元素之和,暴力解法复杂度太大,显 ......
数组 前缀 leetcode amp

LeetCode 周赛 351(2023/06/25)T2 有点意思

> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 和 [BaguTree Pro] 知识星球提问。** - 往期回顾:[LeetCode 单周赛第 348 场 · 数 ......
LeetCode 意思 2023 351 06

LeetCode 双周赛 107(2023/06/24)滑动窗口与离散化

> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 和 [BaguTree Pro] 知识星球提问。** - 往期回顾:[LeetCode 单周赛第 348 场 · 数 ......
LeetCode 2023 107 06 24

【Leetcode每日一题】判定是否互为字符重排

题目 思路 思路比较简单,作两个长度为26的数组,用来存储对应序列字母的个数。遍历完成后对比两个数组,根据是否存在相同序列位置字母个数不一样的情况来确定两个字符串是否都是由相同的字母构成的。 值得一提的是在一开始我忽略了“字母个数必须相同”这一条件。 代码 impl Solution { pub f ......
字符 Leetcode

二叉树-快排-leetcode912

给你一个整数数组 nums,请你将该数组升序排列。 示例 1: 输入:nums = [5,2,3,1] 输出:[1,2,3,5] 示例 2: 输入:nums = [5,1,1,2,0,0] 输出:[0,0,1,1,2,5] 提示: 1 = hi) { return; } // 对 nums[lo.. ......
leetcode 912

[Leetcode] 0026. 删除有序数组中的重复项

# [26. 删除有序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array) 点击上方,跳转至Leetcode ## 题目描述 给你一个 升序排列 的数组 nums ,请你 原地 删除重复出现的元素,使每个 ......
数组 Leetcode 0026

[Leetcode] 0026.删除有序数组中的重复项

# [26. 删除有序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array) [English Version](/solution/0000-0099/0026.Remove%20Duplicates%2 ......
数组 Leetcode 0026

[Leetcode] 0021. 合并两个有序链表

# [21. 合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists) 点击上方,跳转至Leetcode ## 题目描述 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1: ......
Leetcode 两个 0021

【LeetCode摩尔投票】有趣的简单题:数组中出现次数超过一半的数字

### 数组中出现次数超过一半的数字 https://leetcode.cn/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/ 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。 你可以假设数组是非 ......
数组 LeetCode 次数 数字

[leetcode]114. 二叉树展开为链表

总结:怎样写递归函数?关键是把递归函数的功能定义清楚,并在递归函数体中使用自身来做事,此时不要关注递归函数执行的细节。也就是写高层级代码的时候不要关注低层级的事情,这就叫抽象。关注也没有用,想不清楚的。 1 class Solution { 2 public void flatten(TreeNod ......
leetcode 114

[算法学习笔记] Tarjan LCA

在讲解之前,我们先来看一道模板题:[Luogu P3379 最近公共祖先(LCA)](https://www.luogu.com.cn/problem/P3379) ### What is LCA LCA,即最近公共祖先。什么意思呢,我们举个例子: ![image](https://img2023. ......
算法 笔记 Tarjan LCA

LeetCode/子集、组合

###一 . 子集 给你一个整数数组 nums ,数组中的元素 互不相同,返回该数组所有可能的子集 #### 1. 回溯法 对每个数做选择,放入当前位,同时固定访问顺序,只访问下标更大的数,避免重复 回溯法 ``` class Solution { public: vector> res; vect ......
子集 LeetCode

leetcode5最:长回文子串

动态规划: 1个回文串,两边加上同样的字符,也是回文串。这是一个性质,之后要用。 对于一大串字符,从1长度的子串开始判断。 1个长度的子串,肯定回文;如果这个子串两边加上同样的字符,长度变成了3,少了一次判断。 因此还要加上,判断2长度的子串是不是回文。 之后才会判断3长度的子串是不是回文。 以此类 ......
回文 leetcode5 leetcode

LeetCode/特别的排列

给你一个下标从 0 开始的整数数组 nums ,它包含 n 个 互不相同 的正整数。如果 nums 的一个排列满足以下条件,我们称它是一个特别的排列: 对于 0 & nums) { int mod = 1e9+7; int m = nums.size(); int memo[m][m f = [&] ......
LeetCode

做leetcode算法题的一些感受

leetcode题目做了34道了,写下目前的感受,不一定对,需要经常修改内容。 1、代码是怎么写出来的?不是一下子写出来的,是逐步填充,逐步具体的。一句话,写代码也要看到历史和现状,现状不是突然出现的,是有发展历史的。不是从1直接就到10了,而是从1->2->3,逐步递进,最后到10。写代码总要写第 ......
算法 leetcode

Leetcode: Arrays.sort() - comparator

Arrays.sort(points,(o1,o2)->{ if(o1[1] == o2[1]) return 0; if(o1[1] < o2[1]) return -1; return 1; }) 根据dp[1]进行升序排列,O(NlogN) ......
comparator Leetcode Arrays sort

LeetCode--矩形走位

59. 螺旋矩阵 II 定义一个总数,是所有格子走完中心的最大数,target = n*n 从 1 开始,每走一步,当前数 +1 ,while(curNum<=target) 就继续走 定义每圈螺旋走位的边界,初始值:left=0; right=n-1; top=0; bottom=n-1; 1、在 ......
矩形 LeetCode