leetcode minimum split 2578

LeetCode54. 螺旋矩阵Ⅰ

题目描述 给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。 示例 提交的代码 class Solution { public List<Integer> spiralOrder(int[][] matrix) { //行数 int m=matrix.l ......
矩阵 螺旋 LeetCode 54

leetcode45 跳跃游戏2——贪心 (C++/Python)

题目描述: 给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处: 0 <= j <= nums[i] i + j < n ......
leetcode Python 45

LeetCode59. 螺旋矩阵Ⅱ

题目描述 给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix 。 示例 提交的代码 class Solution { int matrixLen=0; public int[][] generateMatrix(int n) ......
矩阵 螺旋 LeetCode 59

leetcode2845. 统计趣味子数组的数目

题解 class Solution { public: long long countInterestingSubarrays(vector<int>& nums, int modulo, int k) { int a[100010]; unordered_map<int, int> mp; mp[ ......
数组 数目 趣味 leetcode 2845

LeetCode Day04 24&19&02.07&142

24. 两两交换链表中的节点 这题使用虚拟头结点会更好做,因为有虚拟头结点我们交换结点的时候步骤会更加清晰。 操作此类有指针类型的题目要注意:1.画图避免混乱 2.注意指针先后顺序 class Solution { public ListNode swapPairs(ListNode head) { ......
amp LeetCode 02.07 Day 142

LeetCode209. 长度最小的子数组

题目描述 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其总和大于等于 target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。 示例 输入:targ ......
数组 长度 LeetCode 209

[LeetCode] 1354. Construct Target Array With Multiple Sums 多次求和构造目标数组

You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure : let x be the sum ......
数组 Construct LeetCode Multiple 目标

Codeforces Round 903 (Div. 3) F. Minimum Maximum Distance(图论)

Codeforces Round 903 (Div. 3) F. Minimum Maximum Distance 思路 对标记点更新fg,从0开始进行bfs,更新d1为所有点到0的距离 获得到0最远的标记点L,从L开始bfs,更新d2为所有点到L的距离 获得距离L最远的标记点R,从R开始bfs,更 ......
Codeforces Distance Minimum Maximum Round

LeetCode题库22.括号生成

class Solution: def generateParenthesis(self, n: int) -> List[str]: if n==1: return ['()'] if not n: return None stack,res,l,r=[],[],[],[] for _ in ra ......
括号 题库 LeetCode 22

Atcoder beginner constest319 Minimum Width

因为要求窗口的最小宽度,当宽度为w时满足条件,那么宽度为w+1时也满足条件,有此可见是有单调性的,那么可以用二分搜的方法,且此题目一定有解。因为M最大为2乘以10的5次方,Li最大为10的9次方,所以宽度最大为2乘以10的14次方,单词每次间隔1,所以这里设成10的17次方。之后就是套二分模板解暴力 ......
beginner constest Atcoder Minimum Width

LeetCode977. 有序数组的平方

题目描述 给你一个按 非递减顺序 排序的整数数组 nums,返回 每个数字的平方 组成的新数组,要求也按 非递减顺序 排序。 示例1 输入:nums = [-4,-1,0,3,10] 输出:[0,1,9,16,100] 解释:平方后,数组变为 [16,1,0,9,100] 排序后,数组变为 [0,1 ......
数组 LeetCode 977

CF1416E Split

暴力 dp 是很拉跨的,我们会设 \(dp_{i,j}\) 表示前 \(i\) 个 \(a_i\) 分裂后,最后一个 \(b\) 为 \(j\) 时的最小答案,爆炸。 但这里面有很多性质啊,直观地我们可以感受到,若已经确定了决策 \(dp_{i-1,k}\),那么无论如何选择 \(a_i\) 的分裂 ......
1416E Split 1416 CF

CF1881F Minimum Maximum Distance

给定一棵树,树上的一些点被打上了标记,定义一个节点的贡献为其到所有标记节点距离的最大值,求最小贡献。 \(n \le 2 \times 10^5\)。 这道题的原题是 CF337D(甚至要更困难一些)。 很套路的换根 DP 啊。我们考虑设 \(f_i\) 为 \(i\) 子树内的标记节点到 \(i\ ......
Distance Minimum Maximum 1881F 1881

LeetCode27. 移除元素

描述 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。 示例1 输入:nums = [3 ......
LeetCode 元素 27

算法训练day30 LeetCode93.78.90

算法训练day30 LeetCode93.78.90 93.复原IP地址 题目 93. 复原 IP 地址 - 力扣(LeetCode) 题解 代码随想录 (programmercarl.com) 使用'.'切割字符串、结束条件为字符串中有三个'.'、同时要确定字符串符合的条件 长度为不为1时,首字符 ......
算法 LeetCode day 30 93

LeetCode704. 二分查找

描述 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。 示例1 输入: nums = [-1,0,3,5,9,12], target = 9 输出: 4 解释: 9 出现在 nu ......
LeetCode 704

[AGC030F] Permutation and Minimum 题解

Permutation and Minimum 看到 300 的数据范围,再加上计数题,很容易就往计数 DP 方向去想。 为方便,我们将 \(n\) 乘二。 因为是两个位置取 \(\min\),于是我们便想到从小往大把每个数填入序列。于是DP数组第一维的意义便出来了:当前已经填入了前 \(i\) 小 ......
题解 Permutation Minimum 030F AGC

Maximums and Minimums (CF E)

思路: 分别求出 最小区间 和最大区间, 利用单调zai 处理即可 然后 在利用 调和级数 , 求最小值的倍数 后记: 为什么我不2个元素都求一个区间呢? ......
Maximums Minimums and CF

LeetCode Day02 977&209&59

第一题是[977. 有序数组的平方]这题解题思路依旧可以用双指针,指针分别指向数组的头尾两端,然后对两端求乘积比较大小,把乘积值更大的存储到数组尾端,然后指针更新位置,代码如下。 public int[] sortedSquares(int[] nums) { //res用于存储平方和结果 int[ ......
amp LeetCode Day 977 209

LeetCode Day01 704. & 27.

###### [704. Binary Search](https://leetcode.cn/problems/binary-search/)入门必备二分查找了。必须是在一堆**有序的**数组中找到其中特定某个val值。###### 二分算法的思路:*首先取一个基准值,这个值我们一般取数组的中间位 ......
LeetCode Day 704 amp 01

【LeetCode递归】括号生成,使用dfs

括号匹配 数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。 示例 1: 输入:n = 3 输出:["((()))","(()())","(())()","()(())","()()()"] 示例 2: 输入:n = 1 输出:["()"] 提示: 1 < ......
括号 LeetCode dfs

[LeetCode] 2863. Maximum Length of Semi-Decreasing Subarrays_Medium tag: stack

You are given an integer array nums. Return the length of the longest semi-decreasing subarray of nums, and 0 if there are no such subarrays. A subarr ......

[LeetCode] 2434. Using a Robot to Print the Lexicographically Smallest String_Medium tag: stack

You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty: Remov ......

LeetCode101.对称二叉树

class Solution { //ArrayDeque不支持添加null public boolean isSymmetric(TreeNode root) { return dfs(root.left,root.right); } // 实际上,递归比较的就是根节点左右子树上,对称位置的节点 ......
LeetCode 101

算法解析:LeetCode——机器人碰撞和最低票价

摘要:本文由葡萄城技术团队原创。转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。 机器人碰撞 问题: 现有 n 个机器人,编号从 1 开始,每个机器人包含在路线上的位置、健康度和移动方向。 给你下标从 0 开始的两个整数数组 positions、health ......
票价 机器人 算法 LeetCode 机器

[LeetCode] 2282. Number of People That Can Be Seen in a Grid_Medium tag: stack.

You are given an m x n 0-indexed 2D array of positive integers heights where heights[i][j] is the height of the person standing at position (i, j). A ......
Grid_Medium LeetCode Number Medium People

Data structure - Stack 小结及leetcode相关题目

Linear data structure - Stack O(1) for push O(1) for pop O(1) for top - Basic skills 先进后出 [LeetCode] 232. Implement Queue using Stacks_Easy tag: stack ......
小结 structure leetcode 题目 Stack

[LeetCode] 1944. Number of Visible People in a Queue_Hard tag: stack

There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers ......
Queue_Hard LeetCode Visible Number People

leetcode122买卖股票的最佳时机——贪心、动态规划

题目描述: 给你一个整数数组 prices ,其中 prices[i] 表示某支股票第 i 天的价格。 在每一天,你可以决定是否购买和/或出售股票。你在任何时候 最多 只能持有 一股 股票。你也可以先购买,然后在 同一天 出售。 返回 你能获得的 最大 利润 。 示例 1: 输入:prices = ......
时机 leetcode 股票 动态 122

LeetCode 383 赎金信

LeetCode 383 赎金信 1. 题目地址 https://leetcode.cn/problems/ransom-note/?envType=study-plan-v2&envId=top-interview-150 2. 题解 这道题是一道哈希表的经典例题,具体步骤如下: 1. 定义哈希表 ......
LeetCode 383