随笔分类 - 算法-刷题题目 / 力扣+acwing
摘要:https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-i/description/ 这个题分两个版本,一个简单的,一个困难的。 给你一个整数\(n\) 和一个二维整数数组 \(queries\)。 有\(
阅读全文
posted @ 2024-08-18 15:52
lipu123
摘要:给你一个长度为\(n\)的整数数组\(nums\),\(n\)是 偶数 ,同时给你一个整数\(k\) 。 你可以对数组进行一些操作。每次操作中,你可以将数组中 任一 元素替换为\(0\)到\(k\)之间的 任一 整数。 执行完所有操作以后,你需要确保最后得到的数组满足以下条件: 存在一个整数\(X\
阅读全文
posted @ 2024-08-12 15:35
lipu123
摘要:https://www.luogu.com.cn/problem/P2758 https://leetcode.cn/problems/edit-distance/description/ 设 \(A\) 和 \(B\) 是两个字符串。我们要用最少的字符操作次数,将字符串 \(A\) 转换为字符串
阅读全文
posted @ 2024-06-24 16:57
lipu123
摘要:https://leetcode.cn/problems/maximize-total-cost-of-alternating-subarrays/description/ 给你一个长度为\(n\)的整数数组\(nums\)。 子数组\(nums[l..r]\)(其中\(0 <= l <= r <
阅读全文
posted @ 2024-06-24 11:22
lipu123
摘要:https://leetcode.cn/problems/search-in-rotated-sorted-array/description/ 整数数组nums按升序排列,数组中的值 互不相同 。 在传递给函数之前,nums 在预先未知的某个下标\(k(0 <= k < nums.length)\
阅读全文
posted @ 2024-06-21 17:52
lipu123
摘要:https://leetcode.cn/problems/maximum-total-damage-with-spell-casting/description/ 一个魔法师有许多不同的咒语。 给你一个数组\(power\),其中每个元素表示一个咒语的伤害值,可能会有多个咒语有相同的伤害值。 已知魔
阅读全文
posted @ 2024-06-17 15:51
lipu123
摘要:这种题一个套路问题 https://www.cnblogs.com/lipu123/p/15435169.html 几乎每一个人都用 乘法表。但是你能在乘法表中快速找到第 k 小的数字吗? 乘法表是大小为\(m x n\)的一个整数矩阵,其中\(mat[i][j] == i * j\)(下标从 1
阅读全文
posted @ 2024-06-13 16:46
lipu123
摘要:https://leetcode.cn/problems/shortest-path-with-alternating-colors/?envType=study-plan-v2&envId=graph-theory 给定一个整数\(n\),即有向图中的节点数,其中节点标记为\(0\)到\(n -
阅读全文
posted @ 2024-06-06 23:17
lipu123
摘要:https://leetcode.cn/problems/continuous-subarray-sum/ 给你一个整数数组\(nums\)和一个整数\(k\),编写一个函数来判断该数组是否含有同时满足下述条件的连续子数组: 子数组大小 至少为\(2\),且 子数组元素总和为\(k\)的倍数。 如果
阅读全文
posted @ 2024-05-24 23:45
lipu123
摘要:给你一个二维数组 edges 表示一个 n 个点的无向图,其中\(edges[i] = [u_i, v_i, length_i]\)表示节点\(u_i\)和节点\(v_i\)之间有一条需要 lengthi 单位时间通过的无向边。 同时给你一个数组\(disappear\),其中\(disappear
阅读全文
posted @ 2024-04-18 16:17
lipu123
摘要:https://leetcode.cn/problems/count-pairs-of-connectable-servers-in-a-weighted-tree-network/description/ 给你一棵无根带权树,树中总共有 n 个节点,分别表示 n 个服务器,服务器从 0 到 n -
阅读全文
posted @ 2024-03-07 20:40
lipu123
摘要:给你一个下标从 0 开始的字符串word 和一个整数k。 在每一秒,你必须执行以下操作: 移除word的前k个字符。 在word的末尾添加k个任意字符。 注意添加的字符不必和移除的字符相同。但是,必须在每一秒钟都执行两种操作。 返回将word恢复到其初始状态所需的最短时间(该时间必须大于零)。 示例
阅读全文
posted @ 2024-02-27 17:56
lipu123
摘要:https://leetcode.cn/problems/number-of-subarrays-that-match-a-pattern-ii/description/ 给你一个下标从\(0\)开始长度为\(n\)的整数数组\(nums\),和一个下标从\(0\)开始长度为\(m\)的整数数组\(
阅读全文
posted @ 2024-02-27 17:30
lipu123
摘要:https://leetcode.cn/problems/find-beautiful-indices-in-the-given-array-ii/description/ 给你一个下标从 \(0\) 开始的字符串\(s\) 、字符串 \(a\) 、字符串 \(b\) 和一个整数 \(k\) 。 如
阅读全文
posted @ 2024-01-17 11:46
lipu123
摘要:https://leetcode.cn/problems/path-with-minimum-effort/description/ 你准备参加一场远足活动。给你一个二维\(rows x columns\)的地图\(heights\),其中\(heights[row][col]\)表示格子\((ro
阅读全文
posted @ 2024-01-10 11:49
lipu123
摘要:使 X 和 Y 相等的最少操作次数 https://leetcode.cn/problems/minimum-number-of-operations-to-make-x-and-y-equal/description/ 给你两个正整数 x 和 y 。 一次操作中,你可以执行以下四种操作之一: 如果
阅读全文
posted @ 2024-01-08 21:29
lipu123
摘要:https://leetcode.cn/problems/find-longest-special-substring-that-occurs-thrice-ii/description/ 给你一个仅由小写英文字母组成的字符串\(s\)。 如果一个字符串仅由单一字符组成,那么它被称为 特殊 字符串。
阅读全文
posted @ 2024-01-02 20:47
lipu123
摘要:链接:https://ac.nowcoder.com/acm/contest/72779/C 来源:牛客网 小红来到了一片沼泽地的岸边,她希望能通过这片沼泽地。 这个沼泽地地图用一个矩阵进行表示。1代表沼泽,0代表平地。小红刚开始在矩阵的左上角,她需要从右下角离开地图。已知进入地图和离开地图的时间可
阅读全文
posted @ 2024-01-02 20:37
lipu123
摘要:二叉树的右视图 给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 示例 1: 输入: [1,2,3,null,5,null,4] 输出: [1,3,4] 示例 2: 输入: [1,null,3] 输出: [1,3] 示例 3: 输入: [
阅读全文
posted @ 2023-12-29 17:29
lipu123
摘要:给定一个长度为\(n\)的整数数组\(height\)。有\(n\)条垂线,第\(i\)条线的两个端点是\((i,0)\)和\((i,height[i])\)。 找出其中的两条线,使得它们与\(x\)轴共同构成的容器可以容纳最多的水。 返回容器可以储存的最大水量。 说明:你不能倾斜容器。 示例 1:
阅读全文
posted @ 2023-12-28 10:33
lipu123