
leetcode马拉松
文章平均质量分 58
村上春树在《当我谈跑步时 我谈些什么》中这样说
““每天不间断地写作,集中意识去工作,这些非做不可——将这样的信息持续不断地传递给身体系统,让它牢牢记住,再悄悄移动刻度,一点一点将极限值向上提升,注意不让身体发觉。”
还有句话我也想说,我就是喜欢。
每天4道leetcode,欢迎大家一起跑马拉松。
云霞川
这个作者很懒,什么都没留下…
展开
-
单源最短路问题
queue 代表刚被更新的点 它有可能更新其他路径 所以检查它的出边。dis[0 ]=0 dis[i]=+OO 只有起点被确定到了。dij实现的时候是通过 将距离设置成无穷大 来表达 不可达。dij 由于边很多, 稠密图 所以用邻接矩阵存即可。dij 需要找n个点 所以外层是一个for循环x。dis[] 代表第k到某一点的最短距离。 t《- 不在s中的距离最近的点。isin代表该点是否在queue中。 用t更新其他点的距离(看下)s:当前已经确定最短路径距离的点。欢迎大家star与fork。原创 2023-05-02 13:18:36 · 686 阅读 · 0 评论 -
基于邻接表的拓扑排序
全部代码在github acwing 上。欢迎大家star与fork。原创 2023-05-02 13:13:05 · 269 阅读 · 0 评论 -
树与图的存储-邻接表与邻接矩阵-深度广度遍历
graph 设置成long long 以防 INT_MAX+l 变成负数。邻接矩阵 采用矩阵存储,graph[i][j] 代表i到j边的权重。邻接表 每个点 用一个单链表 存储它的出边。全部代码在github acwing 上。用一个vis 数组 表示该点是否被访问过。有向图可以采用邻接矩阵与邻接表进行存储。使用一个队列 依次把一个点的队列加入。个人喜欢使用vector实现邻接表。若之间没有边,则为INT_MAX。欢迎star与fork。无论是树 还是无向图。边的序号统一从1开始。原创 2023-05-02 13:07:53 · 582 阅读 · 0 评论 -
深度遍历模版与广度遍历模版
因为斜线的斜率是1,所以 y=x+b. y=-x+b 即可 算出两个方向的截距,通过截距可以唯一确定一条直线。有 “最短路” 的概念, 当图的权重都是为1的时候, 图先找到的都是bfs,最短的。需要额外的数据存储 vis表示是否访问过 dis表示距离。可信性剪枝是判断 走的过程提前判断 ,非法的就没必要走了。但是费空间 o(2^N). 深搜只用o(n)key是列,value是行。从第一行看皇后 能看到放在哪一列。第二个map 存储x+y的截距。第三个map 存储x-y的解决。走的过程中 判断是否在。原创 2023-05-02 12:55:27 · 934 阅读 · 0 评论 -
基础算法-双指针,滑动窗口,位运算,区间离散化
lowbit(x) 返回x的最后一位1后面的数 比如10100 返回100。但我们仅用到了其中的n个数,因此我们可以将它的区间进行映射。就可以通过lowbit 求出 一个数中的1的个数。n的二进制 表示中 第k位数是几 从0开始。输入一个字符串 把每个单词输出出来。需要提前知道要有哪些值 查询和用到。双指针最核心的性质 可以优化。负数即为补码 即为取反+1。不断求它的lowbit即可。具体代码如下 使用二分搜索。比如一个区间 它的大小在。i,j指针最多走2n步。先把第k位移到最后一位。原创 2023-04-13 16:03:00 · 454 阅读 · 0 评论 -
基础算法-大数运算
基础算法-大数运算原创 2023-04-12 15:41:57 · 94 阅读 · 0 评论 -
背包问题-动态规划
动态规划 背包问题原创 2023-04-11 11:30:20 · 412 阅读 · 0 评论 -
lc marathon 10.7
[420. 找到所有好下标](https://leetcode.cn/problems/find-all-good-indices/)[1629. 按键持续时间最长的键原创 2022-10-07 15:07:11 · 117 阅读 · 0 评论 -
leetcode marathon 8.28 复习
leetcode 复习原创 2022-08-28 20:39:05 · 605 阅读 · 0 评论 -
leetcode marathon [复习] 8.24 - 9道
组合,排列,子集排列顺序需要考虑:排列排列顺序不需要考虑:组合,子集组合子集没有重复数字的子集,组合,排列[41. 缺失的第一个正数](https://leetcode-cn.com/problems/first-missing-positive/) -两个思路本地存储跳转遍历[50. Pow(x, n)](https://leetcode-cn.com/problems/powx-n/)记忆化递归[58. 最后一个单词的长度](https://leetcode-cn.com/prob原创 2022-08-24 10:53:52 · 207 阅读 · 0 评论 -
leetcode marathon 过渡
marathon 过渡原创 2022-08-24 08:53:30 · 286 阅读 · 0 评论 -
lc marathon 8.22
[861. 翻转矩阵后的得分](https://leetcode.cn/problems/score-after-flipping-matrix/)九坤-01. 可以读通讯稿的组数[[可以读通讯稿的组数 - 力扣 (LeetCode) 竞赛](https://leetcode.cn/contest/ubiquant2022/problems/xdxykd/)][池塘计数 - 力扣 (LeetCode) 竞赛](https://leetcode.cn/contest/ubiquant2022/proble原创 2022-08-22 20:37:02 · 238 阅读 · 0 评论 -
lc marathon 8.3
[899. 有序队列](https://leetcode.cn/problems/orderly-queue/)[322. 零钱兑换](https://leetcode.cn/problems/coin-change/)[2279. 装满石头的背包的最大数量](https://leetcode.cn/problems/maximum-bags-with-full-capacity-of-rocks/)[334. 递增的三元子序列](https://leetcode.cn/problems/increa原创 2022-08-03 22:09:12 · 151 阅读 · 0 评论 -
lc marathon 8.2
[622. 设计循环队列](https://leetcode.cn/problems/design-circular-queue/)[222. 完全二叉树的节点个数](https://leetcode.cn/problems/count-complete-tree-nodes/)[357. 统计各位数字都不同的数字个数](https://leetcode.cn/problems/count-numbers-with-unique-digits/)[205. 同构字符串](https://leetcod原创 2022-08-02 09:52:45 · 1430 阅读 · 0 评论 -
lc marathon 7.26
[146. LRU 缓存](https://leetcode.cn/problems/lru-cache/)[130. 被围绕的区域](https://leetcode.cn/problems/surrounded-regions/)[133. 克隆图](https://leetcode.cn/problems/clone-graph/)[134. 加油站](https://leetcode.cn/problems/gas-station/)原创 2022-07-26 15:46:09 · 100 阅读 · 0 评论 -
lc marathon 7.23
[81. 搜索旋转排序数组 II](https://leetcode.cn/problems/search-in-rotated-sorted-array-ii/)[452. 用最少数量的箭引爆气球](https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/)[79. 单词搜索 题解 - 力扣(LeetCode)](https://leetcode.cn/problems/word-search/solution/)原创 2022-07-23 11:34:58 · 142 阅读 · 0 评论 -
lc marathon 7.21
[814. 二叉树剪枝](https://leetcode.cn/problems/binary-tree-pruning/)[86. 分隔链表](https://leetcode.cn/problems/partition-list/)[435. 无重叠区间](https://leetcode.cn/problems/non-overlapping-intervals/)原创 2022-07-21 10:38:38 · 97 阅读 · 0 评论 -
lc marathon 7.19
[14. 最长公共前缀](https://leetcode.cn/problems/longest-common-prefix/)[367. 有效的完全平方数](https://leetcode.cn/problems/valid-perfect-square/)[232. 用栈实现队列](https://leetcode.cn/problems/implement-queue-using-stacks/)[342. 4的幂](https://leetcode.cn/problems/power-of原创 2022-07-19 14:33:12 · 117 阅读 · 0 评论 -
lc marathon 7.18
[290. 单词规律](https://leetcode.cn/problems/word-pattern/)[279. 完全平方数](https://leetcode.cn/problems/perfect-squares/)[328. 奇偶链表](https://leetcode.cn/problems/odd-even-linked-list/)[347. 前 K 个高频元素](https://leetcode.cn/problems/top-k-frequent-elements/)...原创 2022-07-18 11:01:16 · 167 阅读 · 0 评论 -
lc marathon 7.16
[138. 复制带随机指针的链表](https://leetcode.cn/problems/copy-list-with-random-pointer/)[剑指 Offer II 092. 翻转字符](https://leetcode.cn/problems/cyJERH/)[面试题 08.09. 括号](https://leetcode.cn/problems/bracket-lcci/)[面试题 05.03. 翻转数位](https://leetcode.cn/problems/reverse-原创 2022-07-16 12:58:24 · 1725 阅读 · 0 评论 -
lc marathon 7.11
[80. 删除有序数组中的重复项 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/)[316. 去除重复字母](https://leetcode.cn/problems/remove-duplicate-letters/)[237. 删除链表中的节点](https://leetcode.cn/problems/delete-node-in-a-linked-list/)...原创 2022-07-11 10:05:44 · 111 阅读 · 0 评论 -
lc marathon 7.9
[169. 多数元素](https://leetcode.cn/problems/majority-element/)[242. 有效的字母异位词](https://leetcode.cn/problems/valid-anagram/)[223. 矩形面积](https://leetcode.cn/problems/rectangle-area/)原创 2022-07-09 21:10:19 · 253 阅读 · 0 评论 -
lc marathon7.8
[82. 删除排序链表中的重复元素 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/)[117. 填充每个节点的下一个右侧节点指针 II](https://leetcode.cn/problems/populating-next-right-pointers-in-each-node-ii/)[97. 交错字符串](https://leetcode.cn/problems/interleaving-string原创 2022-07-08 18:17:33 · 229 阅读 · 0 评论 -
lc marathon 7.7
[313. 超级丑数](https://leetcode.cn/problems/super-ugly-number/)[129. 求根节点到叶节点数字之和](https://leetcode.cn/problems/sum-root-to-leaf-numbers/)[284. 顶端迭代器](https://leetcode.cn/problems/peeking-iterator/)原创 2022-07-07 21:17:14 · 138 阅读 · 0 评论 -
lc marathon 6.30
[263. 丑数](https://leetcode.cn/problems/ugly-number/)[264. 丑数 II](https://leetcode.cn/problems/ugly-number-ii/)[535. TinyURL 的加密与解密](https://leetcode.cn/problems/encode-and-decode-tinyurl/)[258. 各位相加](https://leetcode.cn/problems/add-digits/)...原创 2022-06-30 08:53:52 · 147 阅读 · 0 评论 -
leetcode 马拉松 6.27
剑指 Offer 67. 把字符串转换成整数](https://leetcode.cn/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/)[剑指 Offer 64. 求1+2+…+n](https://leetcode.cn/problems/qiu-12n-lcof/)[剑指 Offer 66. 构建乘积数组](https://leetcode.cn/problems/gou-jian-cheng-ji-shu-zu-lcof/)[剑指原创 2022-06-27 14:13:09 · 116 阅读 · 0 评论 -
lc marathon 2022.6.22
[剑指 Offer 55 - I. 二叉树的深度](https://leetcode.cn/problems/er-cha-shu-de-shen-du-lcof/)[剑指 Offer 56 - I. 数组中数字出现的次数](https://leetcode.cn/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/)[剑指 Offer 56 - II. 数组中数字出现的次数 II](https://leetcode.cn/problems/shu-原创 2022-06-23 17:22:56 · 237 阅读 · 0 评论 -
2021-06.21 lc marathon
[剑指 Offer 53 - II. 0~n-1中缺失的数字](https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/)[剑指 Offer 53 - I. 在排序数组中查找数字 I](https://leetcode.cn/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/)[剑指 Offer 52. 两个链表的第一个公共节点](https://leetcode.cn/problems/liang原创 2022-06-21 13:07:05 · 169 阅读 · 0 评论