├── .gitignore
├── .vscode
├── launch.json
└── settings.json
├── LICENSE
├── README.md
├── animations
├── .vscode
│ ├── launch.json
│ └── settings.json
├── README.md
├── assets
│ ├── code.png
│ ├── code2.png
│ ├── code3.png
│ ├── code4.png
│ ├── logo.jpg
│ └── segment-tree-build.png
├── build.bat
├── colors
│ ├── board.png
│ └── trie.jpg
├── custom_config.yml
├── kmp.py
├── manim_imports_ext.py
├── measure_scene.py
├── merge_videos.py
├── monostack.py
├── quicksort.py
├── rb.py
├── requirements.txt
├── segmenttree.py
├── src
│ ├── algo_avatar.py
│ ├── algo_config.py
│ ├── algo_graph.py
│ ├── algo_logo.py
│ ├── algo_node.py
│ ├── algo_objects.py
│ ├── algo_queue.py
│ ├── algo_rbtree.py
│ ├── algo_scene.py
│ ├── algo_segtree.py
│ ├── algo_speech.py
│ ├── algo_stack.py
│ ├── algo_table.py
│ ├── algo_tree.py
│ ├── algo_trie.py
│ ├── algo_vector.py
│ └── algo_vgroup.py
├── storage
│ └── Tex
│ │ ├── 00fea46a8d0d7b9f.svg
│ │ ├── 04c17a8c3c3d7f3e.svg
│ │ ├── 091899c47bea06cc.svg
│ │ ├── 0b5e738480d63f77.svg
│ │ ├── 102437a744588185.svg
│ │ ├── 1035cbf6c989d88c.svg
│ │ ├── 139489de67029fbd.svg
│ │ ├── 195f4e41af19254f.svg
│ │ ├── 1ca444b2e8849eda.svg
│ │ ├── 206d48c174697b2d.svg
│ │ ├── 21d8f9a0579b36f8.svg
│ │ ├── 2390faa1b6a54602.svg
│ │ ├── 23ac92dd8404b4bb.svg
│ │ ├── 24b6525a6d506052.svg
│ │ ├── 25b1fe2b09ebde73.svg
│ │ ├── 2a34cf4770529f2a.svg
│ │ ├── 2afe91b077bab757.svg
│ │ ├── 2c82aa2d50cdcbce.svg
│ │ ├── 2cd7a0b25e92b8ac.svg
│ │ ├── 303adbd8e2e9e8e5.svg
│ │ ├── 30e01505748804bf.svg
│ │ ├── 31086bd7faacf659.svg
│ │ ├── 3209ad96cc81a7f7.svg
│ │ ├── 32232493a27582c9.svg
│ │ ├── 3302590408b761da.svg
│ │ ├── 331aad5ddcfddd9c.svg
│ │ ├── 33fe4facd06690e5.svg
│ │ ├── 3508f508773385a5.svg
│ │ ├── 373d968ee1a191b6.svg
│ │ ├── 39a393c310282636.svg
│ │ ├── 3b675a05fd20718d.svg
│ │ ├── 3ca95419fdb06525.svg
│ │ ├── 3d903d25f8bef740.svg
│ │ ├── 3fc4e43b693596f4.svg
│ │ ├── 42d2051262fb70d0.svg
│ │ ├── 434f4eeff42d8646.svg
│ │ ├── 45f40c36513c1286.svg
│ │ ├── 4cc5c19b0715aeb8.svg
│ │ ├── 4dbf4dd97cdc176e.svg
│ │ ├── 4e00495a06d6e823.svg
│ │ ├── 507b1393bdfee692.svg
│ │ ├── 50fa0639aa0f8a80.svg
│ │ ├── 534cdbcb6bbb007a.svg
│ │ ├── 5541d63c207d226b.svg
│ │ ├── 566ea9a4e08a514e.svg
│ │ ├── 5956166555ab91d0.svg
│ │ ├── 59d8bc729798accc.svg
│ │ ├── 5a525058771735ce.svg
│ │ ├── 5b1d9df12c498935.svg
│ │ ├── 5e1d42743441c230.svg
│ │ ├── 64721abefd9dec34.svg
│ │ ├── 649b2cedb940d14c.svg
│ │ ├── 685d68401dc5d6ff.svg
│ │ ├── 6a6ac954b5595311.svg
│ │ ├── 6cd26bc34cde498e.svg
│ │ ├── 6efafd03c1284147.svg
│ │ ├── 72138cc67737fa02.svg
│ │ ├── 7350687869cdd447.svg
│ │ ├── 788e0c0489a3f2c3.svg
│ │ ├── 7b9ffe310d75ddcd.svg
│ │ ├── 81d9108b285cbbb7.svg
│ │ ├── 826b0ed5a45a92f4.svg
│ │ ├── 871ddd84617998f6.svg
│ │ ├── 8a2e6f1c2cba3a85.svg
│ │ ├── 8aead2e9a5d7ad58.svg
│ │ ├── 8b1c7ed8c34443d8.svg
│ │ ├── 8b5e7029e1a98ebc.svg
│ │ ├── 8c4d47a6b8618aba.svg
│ │ ├── 8eedaaf507439767.svg
│ │ ├── 8f47798fbb4ee3b5.svg
│ │ ├── 92d35f4a18845e9e.svg
│ │ ├── 9491952bf765a7e5.svg
│ │ ├── 96a253ca951d407e.svg
│ │ ├── 9b0ea4ee170dd429.svg
│ │ ├── 9cfd4567008dd11b.svg
│ │ ├── 9e820e57a89bc104.svg
│ │ ├── 9f985a06c2f80039.svg
│ │ ├── a2f8c7b9e4c1e831.svg
│ │ ├── a72defc9065a4a77.svg
│ │ ├── aa66e2aa28d63d2a.svg
│ │ ├── afa6826b36688dfe.svg
│ │ ├── b0d312d6ca2c35fa.svg
│ │ ├── b1ff84f7b4a13e09.svg
│ │ ├── b29a6b5609a7f71e.svg
│ │ ├── b3431eb514b4085e.svg
│ │ ├── b3b3537f1991df50.svg
│ │ ├── b5cc6433a6446410.svg
│ │ ├── b5d2efdc8748f523.svg
│ │ ├── b74980e0034abad2.svg
│ │ ├── b88e1058ceb75a08.svg
│ │ ├── b9fa880e82b5ca9d.svg
│ │ ├── bb7e37fa89af3825.svg
│ │ ├── bc2f790638a6dde4.svg
│ │ ├── c0422f8737d8b667.svg
│ │ ├── c4621eebc2a911f8.svg
│ │ ├── c56523d1d52489ad.svg
│ │ ├── caec0844c39477d8.svg
│ │ ├── cbcf741d5bb1e7c8.svg
│ │ ├── cbf958847dcef8b7.svg
│ │ ├── cc7c997f94170c05.svg
│ │ ├── cf315f1d4238c71f.svg
│ │ ├── d129edce56fd6002.svg
│ │ ├── d1d2d11d1e74496c.svg
│ │ ├── d3632407b5dcd370.svg
│ │ ├── df91a949f5652883.svg
│ │ ├── e392f78d18181c99.svg
│ │ ├── e63af6b95ba049c8.svg
│ │ ├── e7488bf6d2d5c812.svg
│ │ ├── efdc2f458db5fb97.svg
│ │ ├── f06f7262a5140fc3.svg
│ │ ├── f19927bac22f8153.svg
│ │ ├── f2e8543b7428d720.svg
│ │ ├── f4a80d570f21545d.svg
│ │ ├── f805299b7bea01d0.svg
│ │ ├── fb564dfe8b424430.svg
│ │ ├── fcde92400901e48e.svg
│ │ ├── fe5743ede456daa9.svg
│ │ └── fedc5e2252a1590a.svg
├── test_scene.py
├── tex_scene.py
├── trie.py
└── unionfind.py
├── db
├── codeforces.sqlite
└── leetcode.sqlite
├── docs
├── _config.yml
├── dev_en.md
├── dev_zh.md
├── dotguide.pdf
├── how_to_use_git.md
├── how_to_use_vscode.md
└── index.html
├── images
├── codeforces.svg
├── leetcode_binary_search.svg
├── leetcode_dp.svg
├── leetcode_geometry.svg
├── leetcode_heap_stack_queue.svg
├── leetcode_linked_list.svg
├── leetcode_mini.svg
├── leetcode_string.svg
├── leetcode_tree.svg
├── leetcode_union_find.svg
└── other
│ └── wechat_mp.png
├── map
├── codeforces
│ └── codeforces.txt
├── leetcode
│ ├── leetcode-bfs.txt
│ ├── leetcode-binary-search.txt
│ ├── leetcode-dfs.txt
│ ├── leetcode-dp.txt
│ ├── leetcode-geometry.txt
│ ├── leetcode-graph.txt
│ ├── leetcode-greedy.txt
│ ├── leetcode-heap-stack-queue.txt
│ ├── leetcode-linked-list.txt
│ ├── leetcode-mini.txt
│ ├── leetcode-range.txt
│ ├── leetcode-string.txt
│ ├── leetcode-tree.txt
│ └── leetcode-union-find.txt
├── lightoj.txt
├── luogu.txt
└── pages.txt
├── requirements.txt
├── src
├── codeforces.py
├── codeforces_view.py
├── datamap.py
├── leetcode.py
├── leetcode_view.py
├── main.py
├── platform_view.py
├── query.py
├── theme.py
└── util.py
├── templates
├── binary-index-tree.cpp
├── binary-index-tree.exe
├── kmp.cpp
├── kmp.py
├── quicksort.cpp
├── rb.cpp
├── red-black-tree.cpp
└── segment-tree.cpp
└── user
├── codeforces
├── 10A.Power Consumption Calculation.cpp
├── 1157B.Long Number.cpp
├── 1605A.A.M. Deviation.cpp
├── 1607A.Linear Keyboard.cpp
├── 1607B.Odd Grasshopper.cpp
├── 1607C.Minimum Extraction.cpp
├── 1607D.Blue-Red Permutation.cpp
├── 1607E.Robot on the Board 1.cpp
├── 171E.MYSTERIOUS LANGUAGE.cpp
├── 1A.Theatre Square.cpp
├── 409D.Big Data.cpp
├── 409H.A + B Strikes Back.cpp
├── 4A.Watermelon.cpp
├── 5A.Chat Server's Outgoing Traffic.cpp
├── 6A.Triangle.cpp
├── 71A.Way Too Long Words.cpp
├── 750A.New Year and Hurry.cpp
├── 784E.Twisted Circuit.cpp
├── 785A.Anton and Polyhedrons.cpp
├── 7C.Line.cpp
├── 802M.April Fools' Problem (easy).cpp
├── 855A.Tom Riddle's Diary.cpp
├── 884A.Book Reading.cpp
├── Gym C.Crossword Validation.md
└── touch.txt
└── leetcode
├── 100.相同的树.cpp
├── 1003.检查替换后的词是否有效.cpp
├── 101.对称二叉树.cpp
├── 1019. 链表中的下一个更大节点.cpp
├── 1019.链表中的下一个更大节点.cpp
├── 102.二叉树的层序遍历.cpp
├── 1023.驼峰式匹配.cpp
├── 1032.字符流.cpp
├── 104.二叉树的最大深度.cpp
├── 1046.最后一块石头的重量.cpp
├── 1054.距离相等的条形码.cpp
├── 108.将有序数组转换为二叉搜索树.cpp
├── 109. 有序链表转换二叉搜索树.cpp
├── 1096.花括号展开-ii.cpp
├── 110.平衡二叉树.cpp
├── 1106.解析布尔表达式.cpp
├── 111.二叉树的最小深度.cpp
├── 112.路径总和.cpp
├── 1124.表现良好的最长时间段.cpp
├── 113.路径总和-ii.cpp
├── 1130.叶值的最小代价生成树.cpp
├── 1137.第-n-个泰波那契数.cpp
├── 114.二叉树展开为链表.cpp
├── 1145.二叉树着色游戏.cpp
├── 1155.掷骰子的n种方法.cpp
├── 1155.掷骰子的n种方法.md
├── 1157.子数组中占绝大多数的元素.cpp
├── 116.填充每个节点的下一个右侧节点指针.cpp
├── 1160.拼写单词.cpp
├── 1161.最大层内元素和.cpp
├── 1163.按字典序排在最后的子串.cpp
├── 117.填充每个节点的下一个右侧节点指针-ii.cpp
├── 1171. 从链表中删去总和值为零的连续节点.cpp
├── 118.杨辉三角.cpp
├── 1190.反转每对括号间的子串.cpp
├── 12.整数转罗马数字.cpp
├── 120.三角形最小路径和.cpp
├── 1209.删除字符串中的所有相邻重复项-ii.cpp
├── 121.买卖股票的最佳时机.cpp
├── 122.买卖股票的最佳时机-ii.cpp
├── 122.买卖股票的最佳时机-ii.py
├── 1232.缀点成线.cpp
├── 1249.移除无效的括号.cpp
├── 125.验证回文串.cpp
├── 126.单词接龙-ii.cpp
├── 1261.在受污染的二叉树中查找元素.cpp
├── 1266.访问所有点的最小时间.cpp
├── 1288.删除被覆盖区间.cpp
├── 1289.下降路径最小和-ii.cpp
├── 129.求根到叶子节点数字之和.cpp
├── 1290.二进制链表转整数.cpp
├── 13.罗马数字转整数.cpp
├── 130.被围绕的区域.cpp
├── 1301.最大得分的路径数目.cpp
├── 1302.层数最深叶子节点的和.cpp
├── 1305.两棵二叉搜索树中的所有元素.cpp
├── 1315.祖父节点值为偶数的节点和.cpp
├── 1316.不同的循环子字符串.cpp
├── 1353.最多可以参加的会议数目.cpp
├── 1367. 二叉树中的列表.cpp
├── 1372.二叉树中的最长交错路径.cpp
├── 1373.二叉搜索子树的最大键值和.py
├── 1379.找出克隆二叉树中的相同节点.cpp
├── 138. 复制带随机指针的链表.cpp
├── 1381.设计一个支持增量操作的栈.cpp
├── 1392.最长快乐前缀.cpp
├── 14.最长公共前缀.cpp
├── 1401.圆和矩形是否有重叠.cpp
├── 141. 环形链表.cpp
├── 1410.html-实体解析器.cpp
├── 142. 环形链表 II.cpp
├── 142. 环形链表 II.md
├── 143. 重排链表.cpp
├── 1439.有序矩阵中的第-k-个最小数组和.cpp
├── 144.二叉树的前序遍历.cpp
├── 1443.收集树上所有苹果的最少时间.cpp
├── 1448.统计二叉树中好节点的数目.cpp
├── 1449.数位成本和为目标值的最大数字.cpp
├── 145.二叉树的后序遍历.cpp
├── 1453.圆形靶内的最大飞镖数量.cpp
├── 1457.二叉树中的伪回文路径.cpp
├── 1466.重新规划路线.cpp
├── 147. 对链表进行插入排序.cpp
├── 148. 排序链表.cpp
├── 150.逆波兰表达式求值.cpp
├── 1515.服务中心的最佳位置.cpp
├── 1521.找到最接近目标值的函数值.cpp
├── 1526.形成目标数组的子数组最少增加次数.cpp
├── 1530.好叶子节点对的数量.cpp
├── 154.寻找旋转排序数组中的最小值-ii.cpp
├── 1541.平衡括号字符串的最少插入次数.cpp
├── 1542.找出最长的超赞子字符串.cpp
├── 1544.整理字符串.cpp
├── 155.最小栈.cpp
├── 1585.检查字符串是否可以通过排序子字符串得到另一个字符串.cpp
├── 160. 相交链表.cpp
├── 160.相交链表.md
├── 1600.皇位继承顺序.cpp
├── 1604.警告一小时内使用相同员工卡大于等于三次的人.cpp
├── 1606.找到处理最多请求的服务器.cpp
├── 1609.奇偶树.cpp
├── 1610.可见点的最大数目.cpp
├── 163.缺失的区间.cpp
├── 1638.统计只差一个字符的子串数目.cpp
├── 1641.统计字典序元音字符串的数目.cpp
├── 1641.统计字典序元音字符串的数目.md
├── 1642.可以到达的最远建筑.cpp
├── 1649.通过指令创建有序数组.cpp
├── 1669. 合并两个链表.cpp
├── 167.两数之和-ii-输入有序数组.cpp
├── 1670.设计前中后队列.cpp
├── 1673.找出最具竞争力的子序列.cpp
├── 1675.数组的最小偏移量.cpp
├── 1687.从仓库到码头运输箱子.cpp
├── 17.电话号码的字母组合.cpp
├── 1703.得到连续-k-个-1-的最少相邻交换次数.cpp
├── 1705.吃苹果的最大数目.cpp
├── 1707.与数组中元素的最大异或值.cpp
├── 1719.重构一棵树的方案数.cpp
├── 1721. 交换链表中的节点.cpp
├── 173.二叉搜索树迭代器.cpp
├── 1745.回文串分割-iv.cpp
├── 1753.移除石子的最大得分.cpp
├── 1760.袋子里最少数目的球.cpp
├── 1766.互质树.cpp
├── 1770.执行乘法运算的最大分数.cpp
├── 1803.统计异或值在范围内的数对有多少.cpp
├── 1830.使字符串有序的最少操作次数.cpp
├── 19. 删除链表的倒数第 N 个结点.cpp
├── 1948.删除系统中的重复文件夹.cpp
├── 198.打家劫舍.cpp
├── 199.二叉树的右视图.cpp
├── 2. 两数相加.cpp
├── 20.有效的括号.cpp
├── 200.岛屿数量.cpp
├── 201.数字范围按位与.cpp
├── 203. 移除链表元素.cpp
├── 206. 反转链表.cpp
├── 208.实现-trie-前缀树.cpp
├── 209.长度最小的子数组.cpp
├── 21. 合并两个有序链表.cpp
├── 211.添加与搜索单词-数据结构设计.cpp
├── 212.单词搜索-ii.cpp
├── 213.打家劫舍-ii.cpp
├── 214.最短回文串.cpp
├── 215.数组中的第k个最大元素.cpp
├── 218.天际线问题.cpp
├── 22.括号生成.cpp
├── 220.存在重复元素-iii.cpp
├── 222.完全二叉树的节点个数.cpp
├── 225.用队列实现栈.cpp
├── 226.翻转二叉树.cpp
├── 227.基本计算器-ii.cpp
├── 228.汇总区间.cpp
├── 23.合并k个升序链表.cpp
├── 230.二叉搜索树中第k小的元素.cpp
├── 234.回文链表.cpp
├── 235.二叉搜索树的最近公共祖先.cpp
├── 236.二叉树的最近公共祖先.cpp
├── 237. 删除链表中的节点.cpp
├── 239.滑动窗口最大值.cpp
├── 24. 两两交换链表中的节点.cpp
├── 240.搜索二维矩阵-ii.cpp
├── 25. K 个一组翻转链表.cpp
├── 250.统计同值子树.cpp
├── 257.二叉树的所有路径.cpp
├── 264.丑数-ii.cpp
├── 264.丑数-ii.md
├── 273.整数转换英文表示.cpp
├── 278.第一个错误的版本.cpp
├── 28.实现-str-str.cpp
├── 29.两数相除.cpp
├── 295.数据流的中位数.cpp
├── 3.无重复字符的最长子串.cpp
├── 3.无重复字符的最长子串.md
├── 30.串联所有单词的子串.cpp
├── 303.区域和检索-数组不可变.cpp
├── 304.二维区域和检索-矩阵不可变.cpp
├── 307.区域和检索-数组可修改.cpp
├── 307.区域和检索-数组可修改.md
├── 307.区域和检索-数组可修改s2.cpp
├── 313.超级丑数.cpp
├── 313.超级丑数.md
├── 315.计算右侧小于当前元素的个数.cpp
├── 316.去除重复字母.cpp
├── 32.最长有效括号.cpp
├── 32.最长有效括号.md
├── 327.区间和的个数.cpp
├── 328.奇偶链表.cpp
├── 33.搜索旋转排序数组.cpp
├── 330.按要求补齐数组.cpp
├── 336.回文对.cpp
├── 337.打家劫舍-iii.cpp
├── 34.在排序数组中查找元素的第一个和最后一个位置.cpp
├── 341.扁平化嵌套列表迭代器.cpp
├── 344.反转字符串.cpp
├── 347.前-k-个高频元素.cpp
├── 349.两个数组的交集.cpp
├── 35.搜索插入位置.cpp
├── 350.两个数组的交集-ii.cpp
├── 352.将数据流变为多个不相交区间.cpp
├── 355.设计推特.cpp
├── 357.计算各个位数不同的数字个数.cpp
├── 367.有效的完全平方数.cpp
├── 373.查找和最小的k对数字.cpp
├── 374.猜数字大小.cpp
├── 378.有序矩阵中第-k-小的元素.cpp
├── 38.外观数列.cpp
├── 382.链表随机节点.cpp
├── 383.赎金信.cpp
├── 385.迷你语法分析器.cpp
├── 387.字符串中的第一个唯一字符.cpp
├── 392.判断子序列.cpp
├── 392.判断子序列.py
├── 394.字符串解码.cpp
├── 395.至少有-k-个重复字符的最长子串.cpp
├── 398.随机数索引.cpp
├── 399.除法求值.cpp
├── 4.寻找两个正序数组的中位数.cpp
├── 404.左叶子之和.cpp
├── 407.接雨水-ii.cpp
├── 413.等差数列划分.cpp
├── 413.等差数列划分.md
├── 415.字符串相加.cpp
├── 42.接雨水.cpp
├── 421.数组中两个数的最大异或值.cpp
├── 424.替换后的最长重复字符.cpp
├── 429.n-叉树的层序遍历.cpp
├── 43.字符串相乘.cpp
├── 430.扁平化多级双向链表.cpp
├── 434.字符串中的单词数.cpp
├── 435.无重叠区间.cpp
├── 436.寻找右区间.cpp
├── 437.路径总和-iii.cpp
├── 44.通配符匹配.cpp
├── 443.压缩字符串.cpp
├── 445. 两数相加 II.cpp
├── 448.找到所有数组中消失的数字.cpp
├── 449.序列化和反序列化二叉搜索树.cpp
├── 450.删除二叉搜索树中的节点.cpp
├── 451.根据字符出现频率排序.cpp
├── 455.分发饼干.py
├── 456.132-模式.cpp
├── 459.重复的子字符串.cpp
├── 470.用-rand-7-实现-rand-10.cpp
├── 470.用-rand-7-实现-rand-10.md
├── 472.连接词.cpp
├── 478.在圆内随机生成点.cpp
├── 478.在圆内随机生成点.md
├── 49.字母异位词分组.cpp
├── 493.翻转对.cpp
├── 496.下一个更大元素-i.cpp
├── 5.最长回文子串.cpp
├── 501.二叉搜索树中的众数.cpp
├── 502.ipo.cpp
├── 508.出现次数最多的子树元素和.cpp
├── 509.斐波那契数.cpp
├── 513.找树左下角的值.cpp
├── 520.检测大写字母.cpp
├── 521.最长特殊序列-ⅰ.cpp
├── 53.最大子序和.cpp
├── 53.最大子序和.md
├── 530.二叉搜索树的最小绝对差.cpp
├── 541.反转字符串-ii.cpp
├── 543.二叉树的直径.cpp
├── 547.省份数量.cpp
├── 55.跳跃游戏.py
├── 551.学生出勤记录-i.cpp
├── 557.反转字符串中的单词-iii.cpp
├── 56.合并区间.cpp
├── 563.二叉树的坡度.cpp
├── 564.寻找最近的回文数.cpp
├── 567.字符串的排列.cpp
├── 57.插入区间.cpp
├── 572.另一个树的子树.cpp
├── 576.出界的路径数.cpp
├── 576.出界的路径数.md
├── 58.最后一个单词的长度.cpp
├── 587.安装栅栏.cpp
├── 591.标签验证器.cpp
├── 6.z-字形变换.cpp
├── 605.种花问题.py
├── 606.根据二叉树创建字符串.cpp
├── 61. 旋转链表.cpp
├── 617.合并二叉树.cpp
├── 62.不同路径.cpp
├── 621.任务调度器.cpp
├── 621.任务调度器.md
├── 622.设计循环队列.cpp
├── 63.不同路径-ii.cpp
├── 632.最小区间.cpp
├── 636.函数的独占时间.cpp
├── 637.二叉树的层平均值.cpp
├── 64.最小路径和.cpp
├── 641.设计循环双端队列.cpp
├── 648.单词替换.cpp
├── 65.有效数字.cpp
├── 653.两数之和-iv-输入-bst.cpp
├── 655.输出二叉树.cpp
├── 657.机器人能否返回原点.cpp
├── 659.分割数组为连续子序列.cpp
├── 662.二叉树最大宽度.cpp
├── 67.二进制求和.cpp
├── 671.二叉树中第二小的节点.cpp
├── 676.实现一个魔法字典.cpp
├── 677.键值映射.cpp
├── 68.文本左右对齐.cpp
├── 680.验证回文字符串-ⅱ.cpp
├── 682.棒球比赛.cpp
├── 684.冗余连接.cpp
├── 689.三个无重叠子数组的最大和.cpp
├── 69.x-的平方根.cpp
├── 692.前k个高频单词.cpp
├── 696.计数二进制子串.cpp
├── 699.掉落的方块.cpp
├── 70.爬楼梯.cpp
├── 700.二叉搜索树中的搜索.cpp
├── 703.数据流中的第-k-大元素.cpp
├── 704.二分查找.cpp
├── 707. 设计链表.cpp
├── 71.简化路径.cpp
├── 715.range-模块.cpp
├── 719.找出第-k-小的距离对.cpp
├── 72.编辑距离.cpp
├── 720.词典中最长的单词.cpp
├── 721.账户合并.cpp
├── 725. 分隔链表.cpp
├── 726.原子的数量.cpp
├── 732.我的日程安排表-iii.cpp
├── 735.行星碰撞.cpp
├── 736.lisp-语法解析.cpp
├── 739.每日温度.cpp
├── 739.每日温度.drawio
├── 739.每日温度.md
├── 743.网络延迟时间.cpp
├── 745.前缀和后缀搜索.cpp
├── 746.使用最小花费爬楼梯.cpp
├── 752.打开转盘锁.cpp
├── 76.最小覆盖子串.cpp
├── 761.特殊的二进制序列.cpp
├── 767.重构字符串.cpp
├── 770.基本计算器-iv.cpp
├── 778.水位上升的泳池中游泳.cpp
├── 783.二叉搜索树节点最小距离.cpp
├── 786.第-k-个最小的素数分数.cpp
├── 787.k-站中转内最便宜的航班.cpp
├── 790.多米诺和托米诺平铺.cpp
├── 790.多米诺和托米诺平铺.md
├── 8.字符串转换整数-atoi.cpp
├── 817. 链表组件.cpp
├── 818.赛车.cpp
├── 82. 删除排序链表中的重复元素 II.cpp
├── 83.删除排序链表中重复的元素.cpp
├── 84.柱状图中最大的矩形.cpp
├── 846.一手顺子.cpp
├── 85.最大矩形.cpp
├── 850.矩形面积-ii.cpp
├── 855.考场就座.cpp
├── 856.括号的分数.cpp
├── 857.雇佣-k-名工人的最低成本.cpp
├── 86. 分隔链表.cpp
├── 860.柠檬水找零.py
├── 864.获取所有钥匙的最短路径.cpp
├── 87.扰乱字符串.cpp
├── 871.最低加油次数.cpp
├── 876. 链表的中间结点.cpp
├── 880.索引处的解码字符串.cpp
├── 882.细分图中的可到达结点.cpp
├── 892.三维形体的表面积.cpp
├── 895.最大频率栈.cpp
├── 899.有序队列.cpp
├── 901.股票价格跨度.cpp
├── 907.子数组的最小值之和.cpp
├── 91.解码方法.cpp
├── 91.解码方法.md
├── 92. 反转链表 II.cpp
├── 92.反转链表 II.md
├── 921.使括号有效的最少添加.cpp
├── 931.下降路径最小和.cpp
├── 932.漂亮数组.cpp
├── 933.最近的请求次数.cpp
├── 935.骑士拨号器.cpp
├── 935.骑士拨号器.md
├── 936.戳印序列.cpp
├── 94.二叉树的中序遍历.cpp
├── 944.删列造序.cpp
├── 946.验证栈序列.cpp
├── 95.不同的二叉搜索树-ii.cpp
├── 96.不同的二叉搜索树.cpp
├── 963.最小面积矩形-ii.cpp
├── 968.监控二叉树.cpp
├── 973.最接近原点的-k-个点.cpp
├── 975.奇偶跳.cpp
├── 978.最长湍流子数组.cpp
├── 98.验证二叉搜索树.cpp
├── 981.基于时间的键值存储.py
├── 987.二叉树的垂序遍历.cpp
├── 99.恢复二叉搜索树.cpp
└── kmp.drawio
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | *.gv
3 | *.gv.pdf
4 | out/
5 | *.mp4
6 | __pycache__
7 | animations/videos
8 | templates/a.exe
9 | user/.DS_Store
10 | templates/rb.exe
11 | .vscode/tasks.json
12 | templates/.vscode/tasks.json
13 | templates/red-black-tree.exe
14 | algo_image*.png
15 | animations/storage/mobject_data
16 | animations/storage/Text
17 |
--------------------------------------------------------------------------------
/animations/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "animation",
9 | "type": "python",
10 | "request": "launch",
11 | "module": "manimlib",
12 | "args": ["trie.py", ""]
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/animations/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "python.pythonPath": "C:\\Program Files\\Python39\\python.exe"
3 |
4 |
5 | }
--------------------------------------------------------------------------------
/animations/assets/code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/assets/code.png
--------------------------------------------------------------------------------
/animations/assets/code2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/assets/code2.png
--------------------------------------------------------------------------------
/animations/assets/code3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/assets/code3.png
--------------------------------------------------------------------------------
/animations/assets/code4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/assets/code4.png
--------------------------------------------------------------------------------
/animations/assets/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/assets/logo.jpg
--------------------------------------------------------------------------------
/animations/assets/segment-tree-build.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/assets/segment-tree-build.png
--------------------------------------------------------------------------------
/animations/build.bat:
--------------------------------------------------------------------------------
1 | python3 -m manimlib trie.py -w
--------------------------------------------------------------------------------
/animations/colors/board.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/colors/board.png
--------------------------------------------------------------------------------
/animations/colors/trie.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/animations/colors/trie.jpg
--------------------------------------------------------------------------------
/animations/manim_imports_ext.py:
--------------------------------------------------------------------------------
1 | from manimlib import *
2 | from src.algo_config import *
3 | from src.algo_stack import *
4 | from src.algo_vector import *
5 | from src.algo_scene import *
6 | from src.algo_node import *
7 | from src.algo_vgroup import *
8 | from src.algo_logo import *
9 | from src.algo_graph import *
10 | from src.algo_avatar import *
11 | from src.algo_table import *
12 | from src.algo_objects import *
13 | from src.algo_segtree import *
14 | from src.algo_rbtree import *
15 | from src.algo_trie import *
16 | from src.algo_tree import *
17 |
18 |
--------------------------------------------------------------------------------
/animations/requirements.txt:
--------------------------------------------------------------------------------
1 | graphviz
2 | networkx
3 | PyQt5
4 | pypiwin32
5 | ffmpeg-python
6 | pygraphviz
7 | # 安装64位的graphviz,stable_windows_10_cmake_Release_x64_graphviz-install-2.46.0-win64.exe
8 | # python3 -m pip install --global-option=build_ext --global-option="-IC:\Program Files\Graphviz\include" --global-option="-LC:\Program Files\Graphviz\lib" pygraphviz
9 |
10 |
11 |
--------------------------------------------------------------------------------
/animations/src/algo_config.py:
--------------------------------------------------------------------------------
1 | from PyQt5 import QtWidgets
2 | import sys
3 |
4 | AlgoFontSize = 24
5 | AlgoFontSizeScaleBig = 1.5
6 | AlgoFontSizeScaleNormal = 1.0
7 | AlgoFontSizeScaleSmall = 0.5
8 | AlgoFontSizeScaleVerySmall = 0.3
9 |
10 | AlgoFontName = "Microsoft YaHei"
11 | AlgoSerifFontName = "Source Han Serif CN"
12 | AlgoSansSerifFontName = "Source Han Sans CN"
13 | AlgoMonoFontName = "Consolas"
14 |
15 | def screenScale():
16 | app = QtWidgets.QApplication(sys.argv)
17 | screen = app.primaryScreen()
18 | scale = screen.logicalDotsPerInch()/96.0
19 | return scale
20 |
21 | AlgoScreenScale = screenScale()
22 |
23 |
24 |
--------------------------------------------------------------------------------
/animations/src/algo_queue.py:
--------------------------------------------------------------------------------
1 | from manimlib import *
2 | from .algo_node import *
3 | from .algo_vgroup import *
4 |
5 | class AlgoQueue(AlgoVGroup):
6 | def __init__(self, datas=[], **kwargs):
7 | self.datas = datas
8 | super().__init__(**kwargs)
9 | for k in datas:
10 | self.add(AlgoNode(str(k)))
11 | self.arrange()
12 |
13 | def size(self):
14 | return len(self.datas)
15 |
16 | def push(self, data):
17 | self.add(AlgoNode(str(data)))
18 | self.datas.append(data)
19 | self.arrange()
20 |
21 | def pop(self):
22 | self.remove(self.submobjects[0])
23 | del self.datas[0]
24 | self.arrange()
25 |
26 | def empty(self):
27 | return len(self.datas) == 0
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/animations/src/algo_table.py:
--------------------------------------------------------------------------------
1 | from manimlib import *
2 | import networkx as nx
3 | from .algo_vgroup import *
4 | from .algo_node import *
5 |
6 | class AlgoTable(AlgoVGroup):
7 | def __init__(self, scene, objs, **kwargs):
8 | self.scene = scene
9 | super().__init__(**kwargs)
10 |
11 | v = self
12 | for row in objs:
13 | for c in row:
14 | if isinstance(c, str):
15 | v.add(Text(c).set_color(BLACK).scale(0.3))
16 | else:
17 | v.add(c)
18 | v.arrange_in_grid(n_rows=objs.shape[0], h_buff=0.2, v_buff=0.2)
19 |
20 |
21 |
--------------------------------------------------------------------------------
/animations/src/algo_vgroup.py:
--------------------------------------------------------------------------------
1 | from manimlib import *
2 |
3 | class AlgoVGroup(VGroup):
4 | def __init__(self, *vmobjects, **kwargs):
5 | super().__init__(*vmobjects, **kwargs)
6 |
--------------------------------------------------------------------------------
/animations/storage/Tex/091899c47bea06cc.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/566ea9a4e08a514e.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/6efafd03c1284147.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/826b0ed5a45a92f4.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/a2f8c7b9e4c1e831.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/a72defc9065a4a77.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/b1ff84f7b4a13e09.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/storage/Tex/caec0844c39477d8.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/animations/test_scene.py:
--------------------------------------------------------------------------------
1 | from manim_imports_ext import *
2 |
3 | class TestScene(AlgoScene):
4 | def construct(self):
5 | avatar = AlgoAvatar(self)
6 | avatar.center().scale(0.5)
7 | self.add(avatar)
8 | self.wait(2)
9 |
--------------------------------------------------------------------------------
/db/codeforces.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/db/codeforces.sqlite
--------------------------------------------------------------------------------
/db/leetcode.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/db/leetcode.sqlite
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-slate
--------------------------------------------------------------------------------
/docs/dotguide.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/docs/dotguide.pdf
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 | hello github
--------------------------------------------------------------------------------
/images/other/wechat_mp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/images/other/wechat_mp.png
--------------------------------------------------------------------------------
/map/codeforces/codeforces.txt:
--------------------------------------------------------------------------------
1 | [Codeforces]
2 |
3 | [-基础题]
4 | 1A 4A 5A 6A 750A 784E 785A 802M 855A 1157B
5 |
6 | [-Maths]
7 | 409H
8 |
9 | [-数论-扩展欧几里得算法]
10 | 1478D
11 |
12 | [-动态规划-树形DP]
13 | 1156D
14 |
15 | [-模拟题]
16 | 1493B(key=时间模拟)
17 |
18 |
19 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-bfs.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-BFS搜索]
2 |
3 | [-BFS搜索]
4 | 864
5 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-binary-search.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-二分查找]
2 |
3 | [-第K大数]
4 | 719(key=不是堆)
5 | 778(key=不是堆)
6 | 786(key=不是堆)
7 | 1439(key=二分)
8 |
9 | [-入门题目]
10 | 704(key=入门经典 star=5)
11 | 35(key=入门经典2 star=5)
12 | 69(key=入门平方根)
13 | 278(key=入门)
14 | 367(key=入门平方根)
15 |
16 | [-循环数组]
17 | 33(key=循环偏移后的二分查找 star=5)
18 | 81(key=循环数组)
19 | 153(key=循环数组)
20 | 154
21 |
22 | [-子数组]
23 | 209(key=子数组前缀与二分)
24 |
25 | [-medium]
26 | 34(key=上下界经典题 star=5)
27 | 74(key=搜索二维矩阵 star=5)
28 | 162(key=寻找峰值)
29 | 275 287 300 378 436 454 475 497 528 540 658 718 875 911
30 | 981 1011 1111 1170 1201 1237 1283 1292
31 | 1300 1482 1552 1562 1574 1590 1631 1642 1658
32 | 1712 1760 1802 1818 1855 1856 1870 1884
33 |
34 | [-hard]
35 | 174
36 | 327 352 354 363 410 483 493 668 710
37 | 793 862 878 887 927 1044 1095 1157 1235
38 | 1521 1649 1739 1751 1840 1847 1889
39 |
40 | [-其他类型]
41 | 167(key=双指针)
--------------------------------------------------------------------------------
/map/leetcode/leetcode-dfs.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-DFS搜索]
2 |
3 | [-DFS搜索]
4 | 212(star=5)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-geometry.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-几何]
2 | 892(key=表面积 star=5)
3 | 1232(key=点与线)
4 | 1266(key=斜线与直线)
5 | 963(key=点与矩形)
6 | 1401(key=圆与矩形)
7 | 587(key=多边形与凸包 star=5)
8 | 1453(key=圆与点 star=5)
9 | 1515(key=凸函数最值)
10 | 1610(key=扇形 star=5)
11 |
12 |
13 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-graph.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-图论]
2 |
3 | [-图论]
4 | 882
5 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-greedy.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-贪心]
2 |
3 | [-贪心]
4 | 1353
5 | 605(key=tricky简单题)
6 |
7 | [-序列变化]
8 | 122
9 |
10 | [-排序贪心]
11 | 455(key=经典贪心 star=5)
12 |
13 | [-未分类]
14 | 860 874 944 1005 1046 1217 1221 1403 1518 1710 1716 1725 1736 1758 1784
15 |
16 | 55 134 316 376 402 406 435 452 621 649 659 714 738 763 767
17 | 842 861 870 881 910 921 948 955 984 991 1007 1029 1053 1081
18 | 1090 1094 1111 1247 1253 1276 1282 1288 1296 1338 1353 1386
19 | 1400 1405 1414 1433 1497 1536 1540 1558 1567 1578 1589 1594
20 | 1599 1605 1616 1620 1647 1648 1653 1657 1658 1663 1664 1673 1674
21 | 1685 1686 1689 1702 1705 1717 1722 1727 1733 1737 1743 1749 1754
22 | 1759 1764 1769 1774 1775 1785 1798 1801 1802 1806 1818
23 |
24 | 44 45 135 321 330 502 630 757 765 927 936
25 | 995 1326 1354 1383 1505 1520 1568
26 | 1585 1591 1632 1665 1681 1713 1793 5704
27 |
28 |
29 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-linked-list.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-链表]
2 |
3 | [-链表第一题]
4 | 707(key=链表增删改查)
5 |
6 | [-反转链表]
7 | 234 206 24 25 92 143
8 |
9 | [-删除链表]
10 | 237(key=简单删除) 203(key=删除多个) 83 82 1171(key=区间和)
11 |
12 | [-构建新链表]
13 | 2 445 430 1669 86 328 725 21 23(key=堆)
14 |
15 | [-快慢指针]
16 | 876 19 61 1721 109 141 160(key=路程相等) 142(key=公式推理)
17 |
18 | [-链表和其他算法]
19 | 1290(key=位运算) 817(key=set) 1367(key=二叉树搜索) 1019(key=单调栈) 147(key=插入排序) 148(key=归并排序) 138(key=map映射)
20 |
21 | [-设计题]
22 | 1670
--------------------------------------------------------------------------------
/map/leetcode/leetcode-range.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-区间问题]
2 |
3 | [-区间问题]
4 | 752(key=dp问题)
5 | 56(key=合并重叠区间 star=5)
6 | 57(key=插入合并重叠区间 star=5)
7 | 130(key=2d区域)
8 | 201(key=区间数字位与操作)
9 | 228(key=简单题)
10 | 327(key=Treap树线段树红黑树 star=5)
11 | 330(key=贪心)
12 | 352(key=数据流与区间 star=5)
13 | 435(key=去掉重叠区间 star=5)
14 | 436(key=右侧区间二分 star=5)
15 | 448(key=丢失的数字)
16 | 632(key=最小区间TCS star=5)
17 | 635
18 | 689
19 | 697
20 | 715
21 | 723
22 | 744
23 | 757
24 | 762
25 | 763
26 | 767
27 | 795
28 | 801
29 | 830
30 | 909
31 | 986
32 | 1024
33 | 1272
34 | 1285
35 | 1288
36 | 1326
37 | 1387
38 | 1435
39 | 1450
40 | 1508
41 | 1523
42 | 1787
43 | 1830
44 | 1851
45 | 1854
46 | 1881
47 | 1893
48 |
--------------------------------------------------------------------------------
/map/leetcode/leetcode-union-find.txt:
--------------------------------------------------------------------------------
1 | [Leetcode-并查集]
2 |
3 | [-并查集与搜索]
4 | 130 200
5 | 547(key=基本题)
6 |
7 | [-未分类]
8 | 399 684 721 947 959 990 1202 1319 1584 1631 1722
9 | 128 685 765 778 803 839 924 928 952 1489 1579 1627 1632 1697
10 |
--------------------------------------------------------------------------------
/map/lightoj.txt:
--------------------------------------------------------------------------------
1 | [数论-同余定理]
2 | 1214
--------------------------------------------------------------------------------
/map/luogu.txt:
--------------------------------------------------------------------------------
1 | [luogu]
2 |
3 | [-数据结构-线段树合并]
4 | P4556
--------------------------------------------------------------------------------
/map/pages.txt:
--------------------------------------------------------------------------------
1 | 0x01 https://leetcode-cn.com/circle/article/2Xxlw3/ [leetcode动态规划题目总结]
2 | 0x02 https://github.com/labuladong/fucking-algorithm [刷算法全靠套路,认准 labuladong 就够了]
3 | 0x03 http://svgicons.sparkk.fr/ [svg矢量图标]
4 | 0x04 https://github.com/jennyzzt/AlgoManim [算法动画]
5 | 0x05 https://www.youtube.com/c/BukanCaraCepat/videos [算法动画]
6 | 0x06 https://www.reddit.com/search/?q=manim%20sort%20 [算法动画]
7 | 0x07 https://github.com/llimllib/pymag-trees/ [树形绘制]
8 | 0x08 https://www.youtube.com/watch?v=r6sGWTCMz2k [3b1b动画学习]
9 | 0x09 https://www.youtube.com/watch?v=wTJI_WuZSwE [3b1b动画学习]
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | graphviz == 0.16
2 | requests == 2.18.4
3 | lipsum == 0.1.2
4 | psutil == 5.8.0
5 | psrecord == 1.2
6 | wheel == 0.30.0
7 | sqlitedict == 1.7.0
8 | beautifulsoup4 == 4.9.3
9 | svgpathtools == 1.4.1
10 | lxml == 4.6.2
11 | zhon == 1.1.5
12 | certifi == 2021.10.8
13 |
14 |
--------------------------------------------------------------------------------
/src/main.py:
--------------------------------------------------------------------------------
1 | import leetcode_view
2 | import codeforces_view
3 |
4 | def main():
5 | leetcode_view.process()
6 | codeforces_view.process()
7 |
8 | if __name__ == "__main__":
9 | main()
10 |
--------------------------------------------------------------------------------
/templates/binary-index-tree.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/templates/binary-index-tree.exe
--------------------------------------------------------------------------------
/user/codeforces/10A.Power Consumption Calculation.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int n,p1,p2,p3,t1,t2;
5 | int l,r,s,ans=0;
6 |
7 | int main()
8 | {
9 | scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);
10 | for(int i=1;i<=n;i++)
11 | {
12 | scanf("%d%d",&l,&r);
13 | if(i>1)
14 | {
15 | ans=ans+min(t1,l-s)*p1;
16 | if(l-s>t1)
17 | {
18 | ans=ans+min(l-s-t1,t2)*p2;
19 | if(l-s>t1+t2)
20 | {
21 | ans=ans+(l-s-t1-t2)*p3;
22 | }
23 | }
24 | }
25 | ans=ans+(r-l)*p1;
26 | s=r;
27 | }
28 | printf("%d",ans);
29 |
30 | return 0;
31 | }
32 |
--------------------------------------------------------------------------------
/user/codeforces/1157B.Long Number.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int n,a[200005],b[10];
5 |
6 | int main()
7 | {
8 |
9 | cin>>n;
10 | for(int i=1;i<=n;i++) scanf("%1d",&a[i]);
11 | for(int i=1;i<=9;i++) scanf("%d",&b[i]);
12 | for(int i=1;i<=n;i++)
13 | {
14 | if(a[i]
2 | using namespace std;
3 |
4 | int main()
5 | {
6 | int T;
7 | scanf("%d",&T);
8 | while(T--)
9 | {
10 | long long a,b,c;
11 | scanf("%lld%lld%lld",&a,&b,&c);
12 | cout<<(bool)(abs(a+c-b*2)%3)<<'\n';
13 | }
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/user/codeforces/1607B.Odd Grasshopper.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int t;
5 | long long x,n,res;
6 |
7 | int main()
8 | {
9 | cin>>t;
10 | while(t--)
11 | {
12 | cin>>x>>n;
13 | res=x;
14 | for(long long i=n/4*4+1;i<=n;i++)
15 | {
16 | if(res%2) res+=i;
17 | else res-=i;
18 | }
19 | cout<
2 | using namespace std;
3 |
4 | const long long inf=0x3f3f3f3f3f3f3f3f;
5 | long long n,a[200001],sum=0,mx=-inf;
6 |
7 | int main()
8 | {
9 |
10 | long long t;
11 | scanf("%lld",&t);
12 | while(t--)
13 | {
14 | sum=0,mx=-inf;
15 | scanf("%lld",&n);
16 | for(long long i=1;i<=n;++i) scanf("%lld",&a[i]);
17 | sort(a+1,a+1+n);
18 | for(long long i=1;i<=n;++i)
19 | {
20 | a[i]-=sum;
21 | sum+=a[i];
22 | mx=max(a[i],mx);
23 | }
24 | printf("%lld\n",mx);
25 | }
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/user/codeforces/1607D.Blue-Red Permutation.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int T;
5 | int n,a[200005];
6 | char s[200005];
7 |
8 | bool cmp(int x,int y)
9 | {
10 | return x>y;
11 | }
12 |
13 | int main()
14 | {
15 |
16 | scanf("%d",&T);
17 | begin:
18 | while(T--)
19 | {
20 | vector blue,red;
21 | scanf("%d",&n);
22 | for(int i=1;i<=n;i++)
23 | {
24 | scanf("%d",&a[i]);
25 | }
26 | cin>>s+1;
27 | for(int i=1;i<=n;i++)
28 | {
29 | if(s[i]=='B') blue.push_back(a[i]);
30 | else red.push_back(a[i]);
31 | }
32 | sort(blue.begin(),blue.end());
33 | sort(red.begin(),red.end(),cmp);
34 | for(int i=0;in-i)
37 | {
38 | cout<<"NO"<
2 | using namespace std;
3 |
4 | int T;
5 | int n,m;
6 | string a;
7 |
8 | int main()
9 | {
10 | scanf("%d",&T);
11 | while(T--)
12 | {
13 | scanf("%d%d",&n,&m);
14 | cin>>a;
15 | int x=0,y=0,xmax=0,xmin=0,ymax=0,ymin=0;
16 | for(int i=0;i
2 | using namespace std;
3 |
4 | int n,t,a;
5 |
6 | int main()
7 | {
8 |
9 | scanf("%d%d",&n,&t);
10 | for(int i=1;i<=n;i++)
11 | {
12 | scanf("%d",&a);
13 | t-=(86400-a);
14 | if(t<=0)
15 | {
16 | cout<
2 | using namespace std;
3 |
4 | long long n,m,a;
5 |
6 | int main()
7 | {
8 |
9 |
10 | cin>>n>>m>>a;
11 | cout<<((n-1)/a+1)*((m-1)/a+1);
12 |
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/user/codeforces/409D.Big Data.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | char s[]="1001010111001010";
5 |
6 | int main()
7 | {
8 | int n;
9 | cin>>n;
10 | cout<
2 | #include
3 | using namespace std;
4 | int main(){
5 |
6 | char s1[505]={0},s2[505]={0};
7 | int n1[505]={0},n2[505]={0},ans[505]={0};
8 |
9 | cin>>s1>>s2;
10 |
11 | int l1=strlen(s1);
12 | int l2=strlen(s2);
13 |
14 | for(int i=0;il2?l1:l2;
24 |
25 | for(int i=0;i=10)
29 | {
30 | ans[i]=ans[i]%10;
31 | ans[i+1]++;
32 | }
33 | }
34 |
35 | bool flag=false;
36 |
37 | for(int i=len;i>=0;i--)
38 | {
39 | if(ans[i]!=0||i==0)
40 | {
41 | flag=true;
42 | }
43 |
44 | if(flag)
45 | {
46 | cout<
2 | using namespace std;
3 |
4 | int main(int argc, char *argv[])
5 | {
6 |
7 | int n;
8 | cin>>n;
9 | if(n==2) cout<<"NO"<
2 | using namespace std;
3 |
4 | char a[10001];
5 | int ans = 0, sum = 0;
6 |
7 | int main()
8 | {
9 |
10 | while (gets(a))
11 | {
12 | if (a[0] == '+')
13 | {
14 | sum++;
15 | }
16 | else if (a[0] == '-')
17 | {
18 | sum--;
19 | }
20 | else
21 | {
22 | for (int i = 0; i < strlen(a); i++)
23 | {
24 | if (a[i] == ':')
25 | {
26 | ans += (strlen(a) - i - 1) * sum;
27 | }
28 | }
29 | }
30 | }
31 | cout << ans;
32 |
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/user/codeforces/6A.Triangle.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int a[5];
5 |
6 | int main()
7 | {
8 |
9 | for(int i=1;i<=4;i++) cin>>a[i];
10 | sort(a+1,a+5);
11 | if(a[1]+a[2]>a[3]||a[2]+a[3]>a[4]) cout<<"TRIANGLE"<
2 | using namespace std;
3 | int main()
4 | {
5 |
6 | int n;
7 | string a;
8 | int i;
9 | cin>>n;
10 | for(i=0;i>a;
13 | if(a.length()>10)
14 | {
15 | cout<
2 | using namespace std;
3 |
4 | int n,k;
5 |
6 | int main()
7 | {
8 |
9 | cin>>n>>k;
10 | for(int x=1;x<=n;x++)
11 | {
12 | if(x*(x+1)*2.5+k>240)
13 | {
14 | cout<
2 | using namespace std;
3 |
4 | int iIn1,iIn2,iIn3,iIn4;
5 |
6 | int main()
7 | {
8 |
9 | cin>>iIn1>>iIn2>>iIn3>>iIn4;
10 | cout<<(((iIn1^iIn2)&(iIn3|iIn4))^((iIn2&iIn3)|(iIn1^iIn4)));
11 |
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/user/codeforces/785A.Anton and Polyhedrons.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | string s;
6 | int n;
7 | int ans=0;
8 |
9 | int main()
10 | {
11 |
12 | cin>>n;
13 | while(n--)
14 | {
15 | cin>>s;
16 | if(s[0]=='T')//Tetrahedron
17 | {
18 | ans+=4;
19 | }
20 | if(s[0]=='C')//Cube
21 | {
22 | ans+=6;
23 | }
24 | if(s[0]=='O')//Octahedron
25 | {
26 | ans+=8;
27 | }
28 | if(s[0]=='D')//Dodecahedron
29 | {
30 | ans+=12;
31 | }
32 | if(s[0]=='I')//Icosahedron
33 | {
34 | ans+=20;
35 | }
36 | }
37 | cout<
2 | using namespace std;
3 |
4 | long long a,b,c;
5 | long long x,y;
6 |
7 | int kzo(int a,int b)
8 | {
9 | if(b==0)
10 | {
11 | x=1;
12 | y=0;
13 | return a;
14 | }
15 | long long tmp=kzo(b,a%b);
16 | long long t=x;
17 | x=y;
18 | y=(t-a/b*y);
19 | return tmp;
20 | }
21 |
22 | int main()
23 | {
24 |
25 | scanf("%lld%lld%lld",&a,&b,&c);
26 | c=-c;
27 | long long d=kzo(a,b);
28 | if(c%d!=0)
29 | {
30 | printf("-1\n");
31 | return 0;
32 | }
33 | x=c/d*x,y=c/d*y;
34 | printf("%lld %lld\n",x,y);
35 |
36 | return 0;
37 | }
38 |
--------------------------------------------------------------------------------
/user/codeforces/802M.April Fools' Problem (easy).cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int n,k;
5 | int num=0;
6 | int a[3005];
7 |
8 | int main()
9 | {
10 |
11 | cin>>n>>k;
12 | for(int i=1;i<=n;i++)
13 | {
14 | cin>>a[i];
15 | }
16 | sort(a+1,a+1+n);
17 | for(int i=1;i<=k;i++)
18 | {
19 | num+=a[i];
20 | }
21 | cout<
2 | using namespace std;
3 |
4 | int n,t,a;
5 |
6 | int main()
7 | {
8 |
9 | scanf("%d%d",&n,&t);
10 | for(int i=1;i<=n;i++)
11 | {
12 | scanf("%d",&a);
13 | t-=(86400-a);
14 | if(t<=0)
15 | {
16 | cout< nextLargerNodes(ListNode* head) {
20 | vectorvals;
21 | for(auto i=head;i!=nullptr;i=i->next){
22 | vals.push_back(i->val);
23 | }
24 | vectorres(vals.size(),0);
25 |
26 | int l =vals.size();
27 | for(int i=0;i nextLargerNodes(ListNode* head) {
19 |
20 | }
21 | };
22 | // @lc code=end
23 |
24 |
--------------------------------------------------------------------------------
/user/leetcode/1023.驼峰式匹配.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1023 lang=cpp
3 | *
4 | * [1023] 驼峰式匹配
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector camelMatch(vector& queries, string pattern) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/104.二叉树的最大深度.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=104 lang=cpp
3 | *
4 | * [104] 二叉树的最大深度
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int maxDepth(TreeNode* root) {
22 | if(!root){
23 | return 0;
24 | }
25 | return max(maxDepth(root->left), maxDepth(root->right)) + 1;
26 | }
27 | };
28 | // @lc code=end
29 |
30 |
--------------------------------------------------------------------------------
/user/leetcode/1046.最后一块石头的重量.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1046 lang=cpp
3 | *
4 | * [1046] 最后一块石头的重量
5 | */
6 | #include
7 | using namespace std;
8 |
9 | // @lc code=start
10 | class Solution {
11 | public:
12 | int lastStoneWeight(vector& stones) {
13 | priority_queue q;
14 | for(auto v: stones){
15 | q.emplace(v);
16 | }
17 | while(q.size()>=2){
18 | int a = q.top();
19 | q.pop();
20 | int b = q.top();
21 | q.pop();
22 | q.emplace(abs(a-b));
23 | }
24 | return q.size()?q.top():0;
25 | }
26 | };
27 | // @lc code=end
28 |
29 |
--------------------------------------------------------------------------------
/user/leetcode/1054.距离相等的条形码.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1054 lang=cpp
3 | *
4 | * [1054] 距离相等的条形码
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector rearrangeBarcodes(vector& barcodes) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/108.将有序数组转换为二叉搜索树.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=108 lang=cpp
3 | *
4 | * [108] 将有序数组转换为二叉搜索树
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | TreeNode* sortedArrayToBST(vector& nums) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1096.花括号展开-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1096 lang=cpp
3 | *
4 | * [1096] 花括号展开 II
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector braceExpansionII(string expression) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/110.平衡二叉树.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=110 lang=cpp
3 | *
4 | * [110] 平衡二叉树
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int depth(TreeNode* t){
22 | if(!t)return 0;
23 | return max(depth(t->left), depth(t->right))+1;
24 | }
25 | bool isBalanced(TreeNode* t) {
26 | if(!t)return true;
27 | int l = depth(t->left);
28 | int r = depth(t->right);
29 | if(abs(l-r) > 1){
30 | return false;
31 | }
32 | return isBalanced(t->left) && isBalanced(t->right);
33 | }
34 | };
35 | // @lc code=end
36 |
37 |
--------------------------------------------------------------------------------
/user/leetcode/1106.解析布尔表达式.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1106 lang=cpp
3 | *
4 | * [1106] 解析布尔表达式
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool parseBoolExpr(string expression) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/111.二叉树的最小深度.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=111 lang=cpp
3 | *
4 | * [111] 二叉树的最小深度
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int minDepth(TreeNode* t) {
22 | return 0;
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1124.表现良好的最长时间段.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1124 lang=cpp
3 | *
4 | * [1124] 表现良好的最长时间段
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int longestWPI(vector& hours) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1130.叶值的最小代价生成树.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1130 lang=cpp
3 | *
4 | * [1130] 叶值的最小代价生成树
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int mctFromLeafValues(vector& arr) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1137.第-n-个泰波那契数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1137 lang=cpp
3 | *
4 | * [1137] 第 N 个泰波那契数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int tribonacci(int n) {
11 | int f[n+10];
12 | f[0] = 0;
13 | f[1] = 1;
14 | f[2] = 1;
15 | for(int i=3; i<=n; i++){
16 | f[i] = f[i-1]+f[i-2]+f[i-3];
17 | }
18 | return f[n];
19 | }
20 | };
21 | // @lc code=end
22 |
23 |
--------------------------------------------------------------------------------
/user/leetcode/1145.二叉树着色游戏.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1145 lang=cpp
3 | *
4 | * [1145] 二叉树着色游戏
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class Solution {
18 | public:
19 | bool btreeGameWinningMove(TreeNode* root, int n, int x) {
20 |
21 | }
22 | };
23 | // @lc code=end
24 |
25 |
--------------------------------------------------------------------------------
/user/leetcode/1155.掷骰子的n种方法.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1155 lang=cpp
3 | *
4 | * [1155] 掷骰子的N种方法
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int numRollsToTarget(int d, int f, int target) {
11 | int mod = 1000000007;
12 | int dp[31][1001];
13 | memset(dp, 0, sizeof(dp));
14 |
15 | // 边界起点初始化
16 | // i表示为投掷骰子的个数,j为投掷得到的总点数
17 | int m = min(f, target);
18 | // 投一个骰子,只有一种情况
19 | for(int j = 1; j <= m; j++) {
20 | dp[1][j] = 1;
21 | }
22 |
23 | //进行顺推过程
24 | for(int i = 2; i <=d; i++) {
25 | for(int j = i; j <= i*f; j++) {
26 | for(int k = 1; k<=f && j>=k; k++) {
27 | dp[i][j] += dp[i-1][j-k];
28 | dp[i][j] %= mod;
29 | }
30 | }
31 | }
32 |
33 | return dp[d][target];
34 | }
35 | };
36 | // @lc code=end
37 |
38 |
--------------------------------------------------------------------------------
/user/leetcode/1155.掷骰子的n种方法.md:
--------------------------------------------------------------------------------
1 | #### 题目解析
2 |
3 | 这是一个典型的动态规划问题,得到状态转移方程,dp[i][j] = sum(dp[i-1][j-1], dp[i-1], [j-2], ..., dp[i-1][j-k]), 其中i表示为投掷骰子的个数,j为投掷得到的总点数,k为骰子的面数。
4 |
--------------------------------------------------------------------------------
/user/leetcode/1157.子数组中占绝大多数的元素.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1157 lang=cpp
3 | *
4 | * [1157] 子数组中占绝大多数的元素
5 | */
6 |
7 | // @lc code=start
8 | class MajorityChecker {
9 | public:
10 | MajorityChecker(vector& arr) {
11 |
12 | }
13 |
14 | int query(int left, int right, int threshold) {
15 |
16 | }
17 | };
18 |
19 | /**
20 | * Your MajorityChecker object will be instantiated and called as such:
21 | * MajorityChecker* obj = new MajorityChecker(arr);
22 | * int param_1 = obj->query(left,right,threshold);
23 | */
24 | // @lc code=end
25 |
26 |
--------------------------------------------------------------------------------
/user/leetcode/116.填充每个节点的下一个右侧节点指针.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=116 lang=cpp
3 | *
4 | * [116] 填充每个节点的下一个右侧节点指针
5 | */
6 |
7 | // @lc code=start
8 | /*
9 | // Definition for a Node.
10 | class Node {
11 | public:
12 | int val;
13 | Node* left;
14 | Node* right;
15 | Node* next;
16 |
17 | Node() : val(0), left(NULL), right(NULL), next(NULL) {}
18 |
19 | Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}
20 |
21 | Node(int _val, Node* _left, Node* _right, Node* _next)
22 | : val(_val), left(_left), right(_right), next(_next) {}
23 | };
24 | */
25 |
26 | class Solution {
27 | public:
28 | Node* connect(Node* root) {
29 |
30 | }
31 | };
32 | // @lc code=end
33 |
34 |
--------------------------------------------------------------------------------
/user/leetcode/1160.拼写单词.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1160 lang=cpp
3 | *
4 | * [1160] 拼写单词
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int countCharacters(vector& words, string chars) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1161.最大层内元素和.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1161 lang=cpp
3 | *
4 | * [1161] 最大层内元素和
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int maxLevelSum(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1163.按字典序排在最后的子串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1163 lang=cpp
3 | *
4 | * [1163] 按字典序排在最后的子串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string lastSubstring(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/117.填充每个节点的下一个右侧节点指针-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=117 lang=cpp
3 | *
4 | * [117] 填充每个节点的下一个右侧节点指针 II
5 | */
6 |
7 | // @lc code=start
8 | /*
9 | // Definition for a Node.
10 | class Node {
11 | public:
12 | int val;
13 | Node* left;
14 | Node* right;
15 | Node* next;
16 |
17 | Node() : val(0), left(NULL), right(NULL), next(NULL) {}
18 |
19 | Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}
20 |
21 | Node(int _val, Node* _left, Node* _right, Node* _next)
22 | : val(_val), left(_left), right(_right), next(_next) {}
23 | };
24 | */
25 |
26 | class Solution {
27 | public:
28 | Node* connect(Node* root) {
29 |
30 | }
31 | };
32 | // @lc code=end
33 |
34 |
--------------------------------------------------------------------------------
/user/leetcode/118.杨辉三角.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=118 lang=cpp
3 | *
4 | * [118] 杨辉三角
5 | */
6 | #include
7 | using namespace std;
8 |
9 | // @lc code=start
10 | class Solution {
11 | public:
12 | vector> generate(int n) {
13 | vector> f(n, vector(0, 0));
14 | f[0] = {1};
15 |
16 | for(int i=1; i& prices) {
11 | int n = prices.size();
12 | int f[n];
13 | f[0] = 0;
14 |
15 | // 记录一个当前的最小值
16 | int mi = prices[0];
17 | for(int i=1; i 0){
22 | // 更新较大值
23 | f[i] = max(f[i-1], d);
24 | //printf("f[%d]=%d\n", i, f[i]);
25 | }
26 | mi = min(mi, prices[i]);
27 | }
28 | return f[n-1];
29 | }
30 | };
31 | // @lc code=end
32 |
33 |
--------------------------------------------------------------------------------
/user/leetcode/122.买卖股票的最佳时机-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=122 lang=cpp
3 | *
4 | * [122] 买卖股票的最佳时机 II
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int maxProfit(vector& prices) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/122.买卖股票的最佳时机-ii.py:
--------------------------------------------------------------------------------
1 | #
2 | # @lc app=leetcode.cn id=122 lang=python3
3 | #
4 | # [122] 买卖股票的最佳时机 II
5 | #
6 |
7 | # @lc code=start
8 | class Solution:
9 | def maxProfit(self, prices: List[int]) -> int:
10 | s=0
11 | for i in range(1, len(prices)):
12 | s+=max(0,prices[i]-prices[i-1])
13 | return s
14 | # @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1232.缀点成线.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1232 lang=cpp
3 | *
4 | * [1232] 缀点成线
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool checkStraightLine(vector>& coordinates) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1249.移除无效的括号.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1249 lang=cpp
3 | *
4 | * [1249] 移除无效的括号
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string minRemoveToMakeValid(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/125.验证回文串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=125 lang=cpp
3 | *
4 | * [125] 验证回文串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool isPalindrome(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/126.单词接龙-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=126 lang=cpp
3 | *
4 | * [126] 单词接龙 II
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector> findLadders(string beginWord, string endWord, vector& wordList) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1261.在受污染的二叉树中查找元素.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1261 lang=cpp
3 | *
4 | * [1261] 在受污染的二叉树中查找元素
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class FindElements {
18 | public:
19 | FindElements(TreeNode* root) {
20 |
21 | }
22 |
23 | bool find(int target) {
24 |
25 | }
26 | };
27 |
28 | /**
29 | * Your FindElements object will be instantiated and called as such:
30 | * FindElements* obj = new FindElements(root);
31 | * bool param_1 = obj->find(target);
32 | */
33 | // @lc code=end
34 |
35 |
--------------------------------------------------------------------------------
/user/leetcode/1266.访问所有点的最小时间.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1266 lang=cpp
3 | *
4 | * [1266] 访问所有点的最小时间
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minTimeToVisitAllPoints(vector>& points) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1288.删除被覆盖区间.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1288 lang=cpp
3 | *
4 | * [1288] 删除被覆盖区间
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int removeCoveredIntervals(vector>& intervals) {
11 | // 从左到右,左边相等取较大值
12 | sort(begin(intervals), end(intervals),
13 | [](const vector &o1, const vector &o2) {
14 | return o1[0] == o2[0] ? o2[1] < o1[1] : o1[0] < o2[0];
15 | });
16 |
17 | int count = 0;
18 | int end, prev_end = 0;
19 | for (auto curr : intervals) {
20 | end = curr[1];
21 | // 不包括范围加1
22 | if (prev_end < end) {
23 | ++count;
24 | prev_end = end;
25 | }
26 | }
27 | return count;
28 | }
29 | };
30 | // @lc code=end
31 |
32 |
--------------------------------------------------------------------------------
/user/leetcode/1289.下降路径最小和-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1289 lang=cpp
3 | *
4 | * [1289] 下降路径最小和 II
5 | */
6 |
7 | #include
8 | using namespace std;
9 |
10 | // @lc code=start
11 | class Solution {
12 | public:
13 | int minFallingPathSum(vector>& g) {
14 | int n=g.size();
15 | int f[n][n];
16 |
17 | for(int j=0; jval;
24 | head=head->next;
25 | }
26 |
27 | return res;
28 | }
29 | };
30 | // @lc code=end
--------------------------------------------------------------------------------
/user/leetcode/13.罗马数字转整数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=13 lang=cpp
3 | *
4 | * [13] 罗马数字转整数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int romanToInt(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/130.被围绕的区域.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=130 lang=cpp
3 | *
4 | * [130] 被围绕的区域
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | void solve(vector>& board) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1302.层数最深叶子节点的和.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1302 lang=cpp
3 | *
4 | * [1302] 层数最深叶子节点的和
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class Solution {
18 | public:
19 | int deepestLeavesSum(TreeNode* root) {
20 |
21 | }
22 | };
23 | // @lc code=end
24 |
25 |
--------------------------------------------------------------------------------
/user/leetcode/1305.两棵二叉搜索树中的所有元素.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1305 lang=cpp
3 | *
4 | * [1305] 两棵二叉搜索树中的所有元素
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class Solution {
18 | public:
19 | vector getAllElements(TreeNode* root1, TreeNode* root2) {
20 |
21 | }
22 | };
23 | // @lc code=end
24 |
25 |
--------------------------------------------------------------------------------
/user/leetcode/1315.祖父节点值为偶数的节点和.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1315 lang=cpp
3 | *
4 | * [1315] 祖父节点值为偶数的节点和
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class Solution {
18 | public:
19 | int sumEvenGrandparent(TreeNode* root) {
20 |
21 | }
22 | };
23 | // @lc code=end
24 |
25 |
--------------------------------------------------------------------------------
/user/leetcode/1316.不同的循环子字符串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1316 lang=cpp
3 | *
4 | * [1316] 不同的循环子字符串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int distinctEchoSubstrings(string text) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1353.最多可以参加的会议数目.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1353 lang=cpp
3 | *
4 | * [1353] 最多可以参加的会议数目
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int maxEvents(vector>& events) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1372.二叉树中的最长交错路径.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1372 lang=cpp
3 | *
4 | * [1372] 二叉树中的最长交错路径
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class Solution {
18 | public:
19 | int longestZigZag(TreeNode* root) {
20 |
21 | }
22 | };
23 | // @lc code=end
24 |
25 |
--------------------------------------------------------------------------------
/user/leetcode/1373.二叉搜索子树的最大键值和.py:
--------------------------------------------------------------------------------
1 | #
2 | # @lc app=leetcode.cn id=1373 lang=python3
3 | #
4 | # [1373] 二叉搜索子树的最大键值和
5 | #
6 |
7 | # @lc code=start
8 | # Definition for a binary tree node.
9 | # class TreeNode:
10 | # def __init__(self, val=0, left=None, right=None):
11 | # self.val = val
12 | # self.left = left
13 | # self.right = right
14 | class Solution:
15 | def maxSumBST(self, root: TreeNode) -> int:
16 |
17 | # @lc code=end
18 |
19 |
--------------------------------------------------------------------------------
/user/leetcode/1379.找出克隆二叉树中的相同节点.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1379 lang=cpp
3 | *
4 | * [1379] 找出克隆二叉树中的相同节点
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 |
18 | class Solution {
19 | public:
20 | TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {
21 |
22 | }
23 | };
24 | // @lc code=end
25 |
26 |
--------------------------------------------------------------------------------
/user/leetcode/1381.设计一个支持增量操作的栈.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1381 lang=cpp
3 | *
4 | * [1381] 设计一个支持增量操作的栈
5 | */
6 |
7 | // @lc code=start
8 | class CustomStack {
9 | public:
10 | CustomStack(int maxSize) {
11 |
12 | }
13 |
14 | void push(int x) {
15 |
16 | }
17 |
18 | int pop() {
19 |
20 | }
21 |
22 | void increment(int k, int val) {
23 |
24 | }
25 | };
26 |
27 | /**
28 | * Your CustomStack object will be instantiated and called as such:
29 | * CustomStack* obj = new CustomStack(maxSize);
30 | * obj->push(x);
31 | * int param_2 = obj->pop();
32 | * obj->increment(k,val);
33 | */
34 | // @lc code=end
35 |
36 |
--------------------------------------------------------------------------------
/user/leetcode/1392.最长快乐前缀.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1392 lang=cpp
3 | *
4 | * [1392] 最长快乐前缀
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string longestPrefix(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/14.最长公共前缀.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=14 lang=cpp
3 | *
4 | * [14] 最长公共前缀
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string longestCommonPrefix(vector& strs) {
11 | for(auto s: strs){
12 |
13 | }
14 | }
15 | };
16 | // @lc code=end
17 |
18 |
--------------------------------------------------------------------------------
/user/leetcode/1401.圆和矩形是否有重叠.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1401 lang=cpp
3 | *
4 | * [1401] 圆和矩形是否有重叠
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/141. 环形链表.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=141 lang=cpp
3 | *
4 | * [141] 环形链表
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for singly-linked list.
10 | * struct ListNode {
11 | * int val;
12 | * ListNode *next;
13 | * ListNode(int x) : val(x), next(NULL) {}
14 | * };
15 | */
16 | class Solution {
17 | public:
18 | bool hasCycle(ListNode *head) {
19 | if(head==nullptr ||head->next==nullptr) return false;
20 |
21 | ListNode*slow=head,*fast=head;
22 | while(fast){
23 | slow=slow->next;
24 | fast=fast->next;
25 | if(fast) fast=fast->next;
26 | if(fast==slow) return true;
27 | }
28 | return false;
29 | }
30 | };
31 | // @lc code=end
--------------------------------------------------------------------------------
/user/leetcode/1410.html-实体解析器.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1410 lang=cpp
3 | *
4 | * [1410] HTML 实体解析器
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string entityParser(string text) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1439.有序矩阵中的第-k-个最小数组和.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1439 lang=cpp
3 | *
4 | * [1439] 有序矩阵中的第 k 个最小数组和
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int kthSmallest(vector>& mat, int k) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/144.二叉树的前序遍历.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=144 lang=cpp
3 | *
4 | * [144] 二叉树的前序遍历
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | vector preorderTraversal(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1443.收集树上所有苹果的最少时间.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1443 lang=cpp
3 | *
4 | * [1443] 收集树上所有苹果的最少时间
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minTime(int n, vector>& edges, vector& hasApple) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1448.统计二叉树中好节点的数目.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1448 lang=cpp
3 | *
4 | * [1448] 统计二叉树中好节点的数目
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int goodNodes(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1449.数位成本和为目标值的最大数字.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1449 lang=cpp
3 | *
4 | * [1449] 数位成本和为目标值的最大数字
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string largestNumber(vector& cost, int target) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/145.二叉树的后序遍历.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=145 lang=cpp
3 | *
4 | * [145] 二叉树的后序遍历
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | vector postorderTraversal(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1453.圆形靶内的最大飞镖数量.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1453 lang=cpp
3 | *
4 | * [1453] 圆形靶内的最大飞镖数量
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int numPoints(vector>& points, int r) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1457.二叉树中的伪回文路径.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1457 lang=cpp
3 | *
4 | * [1457] 二叉树中的伪回文路径
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int pseudoPalindromicPaths (TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1466.重新规划路线.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1466 lang=cpp
3 | *
4 | * [1466] 重新规划路线
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minReorder(int n, vector>& connections) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1515.服务中心的最佳位置.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1515 lang=cpp
3 | *
4 | * [1515] 服务中心的最佳位置
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | double getMinDistSum(vector>& positions) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1521.找到最接近目标值的函数值.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1521 lang=cpp
3 | *
4 | * [1521] 找到最接近目标值的函数值
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int closestToTarget(vector& arr, int target) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1526.形成目标数组的子数组最少增加次数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1526 lang=cpp
3 | *
4 | * [1526] 形成目标数组的子数组最少增加次数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minNumberOperations(vector& target) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1530.好叶子节点对的数量.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1530 lang=cpp
3 | *
4 | * [1530] 好叶子节点对的数量
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int countPairs(TreeNode* root, int distance) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/154.寻找旋转排序数组中的最小值-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=154 lang=cpp
3 | *
4 | * [154] 寻找旋转排序数组中的最小值 II
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int findMin(vector& nums) {
11 | int low = 0;
12 | int high = nums.size() - 1;
13 | while (low < high) {
14 | int m = low + (high - low) / 2;
15 | if (nums[m] < nums[high]) {
16 | high = m;
17 | }
18 | else if (nums[m] > nums[high]) {
19 | low = m + 1;
20 | }
21 | else {
22 | high -= 1;
23 | }
24 | }
25 | return nums[low];
26 | }
27 | };
28 | // @lc code=end
29 |
30 |
--------------------------------------------------------------------------------
/user/leetcode/1541.平衡括号字符串的最少插入次数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1541 lang=cpp
3 | *
4 | * [1541] 平衡括号字符串的最少插入次数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minInsertions(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1542.找出最长的超赞子字符串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1542 lang=cpp
3 | *
4 | * [1542] 找出最长的超赞子字符串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int longestAwesome(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1544.整理字符串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1544 lang=cpp
3 | *
4 | * [1544] 整理字符串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string makeGood(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/155.最小栈.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=155 lang=cpp
3 | *
4 | * [155] 最小栈
5 | */
6 |
7 | // @lc code=start
8 | class MinStack {
9 | public:
10 | /** initialize your data structure here. */
11 | MinStack() {
12 |
13 | }
14 |
15 | void push(int x) {
16 |
17 | }
18 |
19 | void pop() {
20 |
21 | }
22 |
23 | int top() {
24 |
25 | }
26 |
27 | int getMin() {
28 |
29 | }
30 | };
31 |
32 | /**
33 | * Your MinStack object will be instantiated and called as such:
34 | * MinStack* obj = new MinStack();
35 | * obj->push(x);
36 | * obj->pop();
37 | * int param_3 = obj->top();
38 | * int param_4 = obj->getMin();
39 | */
40 | // @lc code=end
41 |
42 |
--------------------------------------------------------------------------------
/user/leetcode/1585.检查字符串是否可以通过排序子字符串得到另一个字符串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1585 lang=cpp
3 | *
4 | * [1585] 检查字符串是否可以通过排序子字符串得到另一个字符串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool isTransformable(string s, string t) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/160. 相交链表.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=160 lang=cpp
3 | *
4 | * [160] 相交链表
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for singly-linked list.
10 | * struct ListNode {
11 | * int val;
12 | * ListNode *next;
13 | * ListNode(int x) : val(x), next(NULL) {}
14 | * };
15 | */
16 | // 构造一段路程,使得两个指针相遇的时候走过的路程相等 空间O(1) 时间O(N)
17 | // 使用一个set记录 空间O(n) 时间O(N)
18 | class Solution {
19 | public:
20 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
21 | //if(headA==nullptr || headB==nullptr) return nullptr;
22 |
23 | ListNode*a=headA,*b=headB;
24 | while(a!=b){
25 | if(a!=nullptr) a=a->next;
26 | else a=headB;
27 |
28 | if(b!=nullptr) b=b->next;
29 | else b=headA;
30 | }
31 | return a;
32 | }
33 | };
34 | // @lc code=end
35 |
--------------------------------------------------------------------------------
/user/leetcode/160.相交链表.md:
--------------------------------------------------------------------------------
1 | ### 160. 相交链表
2 | 编写一个程序,找到两个单链表相交的起始节点。
3 |
4 | ### 样例
5 | #### 输入
6 | ```
7 | intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
8 | ```
9 | 输入解释:相交节点的值为 8 (注意,如果两个链表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。
10 | #### 输出
11 | ```
12 | Reference of the node with value = 8
13 | ```
14 | ### 题目分析
15 | 题目要求相交的节点,相交意味着相交之后链表的结点数量相同。那么如何使得相交之前的差异被消除呢?于是想到只要把两个链表的不相交部分都走一遍那么路程一定相等。
16 | 如果两个链表相交,用两个指针,一个先走A,再走B。另一个先走B,再走A。第二次到达相交点时,两指针走过的路程相等。
17 |
18 | #### 代码实现
19 | ``` c++
20 | class Solution {
21 | public:
22 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
23 | //if(headA==nullptr || headB==nullptr) return nullptr;
24 |
25 | ListNode*a=headA,*b=headB;
26 | while(a!=b){
27 | if(a!=nullptr) a=a->next;
28 | else a=headB;
29 |
30 | if(b!=nullptr) b=b->next;
31 | else b=headA;
32 | }
33 | return a;
34 | }
35 | };
36 | ```
--------------------------------------------------------------------------------
/user/leetcode/1600.皇位继承顺序.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1600 lang=cpp
3 | *
4 | * [1600] 皇位继承顺序
5 | */
6 |
7 | // @lc code=start
8 | class ThroneInheritance {
9 | public:
10 | ThroneInheritance(string kingName) {
11 |
12 | }
13 |
14 | void birth(string parentName, string childName) {
15 |
16 | }
17 |
18 | void death(string name) {
19 |
20 | }
21 |
22 | vector getInheritanceOrder() {
23 |
24 | }
25 | };
26 |
27 | /**
28 | * Your ThroneInheritance object will be instantiated and called as such:
29 | * ThroneInheritance* obj = new ThroneInheritance(kingName);
30 | * obj->birth(parentName,childName);
31 | * obj->death(name);
32 | * vector param_3 = obj->getInheritanceOrder();
33 | */
34 | // @lc code=end
35 |
36 |
--------------------------------------------------------------------------------
/user/leetcode/1609.奇偶树.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1609 lang=cpp
3 | *
4 | * [1609] 奇偶树
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | bool isEvenOddTree(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/1610.可见点的最大数目.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1610 lang=cpp
3 | *
4 | * [1610] 可见点的最大数目
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int visiblePoints(vector>& points, int angle, vector& location) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/163.缺失的区间.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/user/leetcode/163.缺失的区间.cpp
--------------------------------------------------------------------------------
/user/leetcode/1638.统计只差一个字符的子串数目.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1638 lang=cpp
3 | *
4 | * [1638] 统计只差一个字符的子串数目
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int countSubstrings(string s, string t) {
11 | int m = s.size();
12 | int n = t.size();
13 | int ans = 0;
14 | for (int i = 0; i < m; ++i) {
15 | for (int j = 0; j < n; ++j) {
16 | int diff = 0;
17 | for (int k = 0; i + k < m && j + k < n; ++k) {
18 | diff += (s[i + k] != t[j + k]);
19 | if (diff > 1) {
20 | break;
21 | }
22 | if (diff == 1) {
23 | ++ans;
24 | }
25 | }
26 | }
27 | }
28 | return ans;
29 | }
30 | };
31 | // @lc code=end
32 |
33 |
--------------------------------------------------------------------------------
/user/leetcode/1641.统计字典序元音字符串的数目.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1641 lang=cpp
3 | *
4 | * [1641] 统计字典序元音字符串的数目
5 | */
6 |
7 | // @lc code=start
8 | class Solution
9 | {
10 | public:
11 | int countVowelStrings(int n)
12 | {
13 | if (n == 0)
14 | return 0;
15 | if (n == 1)
16 | return 5;
17 | int ans[n + 1][5];
18 | ans[1][0] = 1;
19 | ans[1][1] = 2;
20 | ans[1][2] = 3;
21 | ans[1][3] = 4;
22 | ans[1][4] = 5;
23 | for (int i = 2; i <= n; i++)
24 | {
25 | for (int j = 0; j < 5; j++)
26 | {
27 | if (j == 0)
28 | ans[i][j] = ans[i - 1][j];
29 | else
30 | ans[i][j] = ans[i - 1][j] + ans[i][j - 1];
31 | }
32 | }
33 | return ans[n][4];
34 | }
35 | };
36 | // @lc code=end
37 |
--------------------------------------------------------------------------------
/user/leetcode/1641.统计字典序元音字符串的数目.md:
--------------------------------------------------------------------------------
1 | ### 解题思路一
2 | 动态规划
3 | 两重循环,复杂度为O(n)
4 |
5 | 长度为 i 且以第 j 个元音为结尾的字符串数量 = 长度为 i - 1 且以小于等于 j 元音为结尾的字符串数量的和
6 |
7 | dp[i][j]保存的状态为 长度为 i 且以大于等于 j 元音为结尾的字符串数量的和
8 |
9 | 所以有状态转移方程
10 |
11 | dp[i][j] =dp[i-1][j] +dp[i][j-1];
12 |
13 | 代码是比赛时写的,还算比较简洁的
14 |
15 | ### 解题思路二
16 | 排列组合,隔板法
17 | 看了大佬的思路,真的神阿
18 | 因为需要按照字典序排列,所以只要确定了每个元音出现的次数就可以唯一确定一个序列
19 | 对应长度为n的序列,需要分成5份,但是不能重复选,因为每个板子要有先后顺序,这里可以预设每个字母至少有一次。
20 | 所以先为每个字母分配一个,这样一共就有n+5个字母,有n+4个位置可以放板子,要放四个板子
21 | 图中每个字母出现次数最后需要减去之前多给的一次
22 |
23 | 最后得出公式 (n+4)(n+3)(n+2)*(n+1)/24;
--------------------------------------------------------------------------------
/user/leetcode/1642.可以到达的最远建筑.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1642 lang=cpp
3 | *
4 | * [1642] 可以到达的最远建筑
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int furthestBuilding(vector& heights, int bricks, int ladders) {
11 | int n = heights.size();
12 | // 由于我们需要维护最大的 l 个值,因此使用小根堆
13 | priority_queue, greater> q;
14 | // 需要使用砖块的 delta h 的和
15 | int s = 0;
16 | for (int i = 1; i < n; ++i) {
17 | int d = heights[i] - heights[i - 1];
18 | if (d > 0) {
19 | q.push(d);
20 | // 如果优先队列已满,需要拿出一个其中的最小值,改为使用砖块
21 | if (q.size() > ladders) {
22 | s += q.top();
23 | q.pop();
24 | }
25 | if (s > bricks) {
26 | return i - 1;
27 | }
28 | }
29 | }
30 | return n - 1;
31 | }
32 | };
33 | // @lc code=end
34 |
35 |
--------------------------------------------------------------------------------
/user/leetcode/1649.通过指令创建有序数组.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1649 lang=cpp
3 | *
4 | * [1649] 通过指令创建有序数组
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int createSortedArray(vector& instructions) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/167.两数之和-ii-输入有序数组.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=167 lang=cpp
3 | *
4 | * [167] 两数之和 II - 输入有序数组
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector twoSum(vector& numbers, int target) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1670.设计前中后队列.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1670 lang=cpp
3 | *
4 | * [1670] 设计前中后队列
5 | */
6 |
7 | // @lc code=start
8 | class FrontMiddleBackQueue {
9 | public:
10 | FrontMiddleBackQueue() {
11 |
12 | }
13 |
14 | void pushFront(int val) {
15 |
16 | }
17 |
18 | void pushMiddle(int val) {
19 |
20 | }
21 |
22 | void pushBack(int val) {
23 |
24 | }
25 |
26 | int popFront() {
27 |
28 | }
29 |
30 | int popMiddle() {
31 |
32 | }
33 |
34 | int popBack() {
35 |
36 | }
37 | };
38 |
39 | /**
40 | * Your FrontMiddleBackQueue object will be instantiated and called as such:
41 | * FrontMiddleBackQueue* obj = new FrontMiddleBackQueue();
42 | * obj->pushFront(val);
43 | * obj->pushMiddle(val);
44 | * obj->pushBack(val);
45 | * int param_4 = obj->popFront();
46 | * int param_5 = obj->popMiddle();
47 | * int param_6 = obj->popBack();
48 | */
49 | // @lc code=end
50 |
51 |
--------------------------------------------------------------------------------
/user/leetcode/1673.找出最具竞争力的子序列.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1673 lang=cpp
3 | *
4 | * [1673] 找出最具竞争力的子序列
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector mostCompetitive(vector& nums, int k) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1675.数组的最小偏移量.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1675 lang=cpp
3 | *
4 | * [1675] 数组的最小偏移量
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minimumDeviation(vector& nums) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1687.从仓库到码头运输箱子.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1687 lang=cpp
3 | *
4 | * [1687] 从仓库到码头运输箱子
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int boxDelivering(vector>& boxes, int portsCount, int maxBoxes, int maxWeight) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/17.电话号码的字母组合.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=17 lang=cpp
3 | *
4 | * [17] 电话号码的字母组合
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector letterCombinations(string digits) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1703.得到连续-k-个-1-的最少相邻交换次数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1703 lang=cpp
3 | *
4 | * [1703] 得到连续 K 个 1 的最少相邻交换次数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minMoves(vector& nums, int k) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1705.吃苹果的最大数目.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1705 lang=cpp
3 | *
4 | * [1705] 吃苹果的最大数目
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int eatenApples(vector& apples, vector& days) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1719.重构一棵树的方案数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1719 lang=cpp
3 | *
4 | * [1719] 重构一棵树的方案数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int checkWays(vector>& pairs) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/173.二叉搜索树迭代器.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=173 lang=cpp
3 | *
4 | * [173] 二叉搜索树迭代器
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class BSTIterator {
20 | public:
21 | BSTIterator(TreeNode* root) {
22 |
23 | }
24 |
25 | int next() {
26 |
27 | }
28 |
29 | bool hasNext() {
30 |
31 | }
32 | };
33 |
34 | /**
35 | * Your BSTIterator object will be instantiated and called as such:
36 | * BSTIterator* obj = new BSTIterator(root);
37 | * int param_1 = obj->next();
38 | * bool param_2 = obj->hasNext();
39 | */
40 | // @lc code=end
41 |
42 |
--------------------------------------------------------------------------------
/user/leetcode/1753.移除石子的最大得分.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1753 lang=cpp
3 | *
4 | * [1753] 移除石子的最大得分
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int maximumScore(int a, int b, int c) {
11 | priority_queue q;
12 | int ans = 0;
13 | q.push(a);
14 | q.push(b);
15 | q.push(c);
16 | while(true){
17 | int max_num = q.top();
18 | q.pop();
19 | int medium = q.top();
20 | q.pop();
21 | int min_num = q.top();
22 | if(!medium)break; //结束条件
23 | int temp = max(medium - min_num, 1); //我要从最多的两堆里拿多少
24 | max_num -= temp;
25 | medium -= temp;
26 | ans += temp; //更新答案
27 | q.push(max_num);
28 | q.push(medium);
29 | }
30 | return ans;
31 | }
32 | };
33 | // @lc code=end
34 |
35 |
--------------------------------------------------------------------------------
/user/leetcode/1760.袋子里最少数目的球.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1760 lang=cpp
3 | *
4 | * [1760] 袋子里最少数目的球
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minimumSize(vector& nums, int maxOperations) {
11 | int left = 1, right = *max_element(nums.begin(), nums.end());
12 | int ans = 0;
13 | while (left <= right) {
14 | int y = (left + right) / 2;
15 | long long ops = 0;
16 | for (int x: nums) {
17 | ops += (x - 1) / y;
18 | }
19 | if (ops <= maxOperations) {
20 | ans = y;
21 | right = y - 1;
22 | }
23 | else {
24 | left = y + 1;
25 | }
26 | }
27 | return ans;
28 | }
29 | };
30 | // @lc code=end
31 |
32 |
--------------------------------------------------------------------------------
/user/leetcode/1766.互质树.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1766 lang=cpp
3 | *
4 | * [1766] 互质树
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector getCoprimes(vector& nums, vector>& edges) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1803.统计异或值在范围内的数对有多少.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1803 lang=cpp
3 | *
4 | * [1803] 统计异或值在范围内的数对有多少
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int countPairs(vector& nums, int low, int high) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1830.使字符串有序的最少操作次数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1830 lang=cpp
3 | *
4 | * [1830] 使字符串有序的最少操作次数
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int makeStringSorted(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/1948.删除系统中的重复文件夹.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=1948 lang=cpp
3 | *
4 | * [1948] 删除系统中的重复文件夹
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector> deleteDuplicateFolder(vector>& paths) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/198.打家劫舍.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=198 lang=cpp
3 | *
4 | * [198] 打家劫舍
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int rob(vector& nums) {
11 | int n = nums.size();
12 | if(n == 0){
13 | return 0;
14 | }
15 | if(n == 1){
16 | return nums[0];
17 | }
18 | int f[n+10];
19 | f[0] = nums[0];
20 | f[1] = nums[1];
21 | for(int i=2; i rightSideView(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/2. 两数相加.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=2 lang=cpp
3 | *
4 | * [2] 两数相加
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for singly-linked list.
10 | * struct ListNode {
11 | * int val;
12 | * ListNode *next;
13 | * ListNode() : val(0), next(nullptr) {}
14 | * ListNode(int x) : val(x), next(nullptr) {}
15 | * ListNode(int x, ListNode *next) : val(x), next(next) {}
16 | * };
17 | */
18 | class Solution {
19 | public:
20 | ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
21 | ListNode* sentry=new ListNode(0,l1);
22 | ListNode* curr = sentry;
23 | int temp=0;
24 | while(l1 || l2){ //一直加 直到l1和l2都为空
25 | if(l1) {temp+=l1->val;l1=l1->next;}
26 | if(l2) {temp+=l2->val;l2=l2->next;}
27 | curr->next = new ListNode(temp%10,nullptr);
28 | curr=curr->next;
29 | temp =temp/10;
30 | }
31 | if(temp) curr->next=new ListNode(temp,nullptr);
32 | return sentry->next;
33 | }
34 | };
35 | // @lc code=end
--------------------------------------------------------------------------------
/user/leetcode/20.有效的括号.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=20 lang=cpp
3 | *
4 | * [20] 有效的括号
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool isValid(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/200.岛屿数量.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=200 lang=cpp
3 | *
4 | * [200] 岛屿数量
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int numIslands(vector>& grid) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/201.数字范围按位与.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=201 lang=cpp
3 | *
4 | * [201] 数字范围按位与
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int rangeBitwiseAnd(int left, int right) {
11 | int i = 1;
12 | if (left == right) {
13 | return left;
14 | }
15 | if (left == 0 ) {
16 | return 0;
17 | }
18 |
19 | if (left >= 1073741824) {
20 | return 1073741824 + rangeBitwiseAnd(left-(1073741824), right-(1073741824));
21 | }
22 |
23 | i = 1;
24 | while (left >= i) {
25 | i *= 2;
26 | }
27 |
28 | if (right >= i) {
29 | return 0;
30 | }
31 | else {
32 | return i/2 + rangeBitwiseAnd(left-(i/2), right-(i/2));
33 | }
34 | }
35 | };
36 |
37 | // @lc code=end
38 |
39 |
--------------------------------------------------------------------------------
/user/leetcode/203. 移除链表元素.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=203 lang=cpp
3 | *
4 | * [203] 移除链表元素
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for singly-linked list.
10 | * struct ListNode {
11 | * int val;
12 | * ListNode *next;
13 | * ListNode() : val(0), next(nullptr) {}
14 | * ListNode(int x) : val(x), next(nullptr) {}
15 | * ListNode(int x, ListNode *next) : val(x), next(next) {}
16 | * };
17 | */
18 | class Solution {
19 | public:
20 | ListNode* removeElements(ListNode* head, int val) {
21 | if(head==nullptr) return head;
22 |
23 | head->next=removeElements(head->next,val);
24 | if(head->val==val) return head->next;
25 | return head;
26 | }
27 | };
28 | // @lc code=end
--------------------------------------------------------------------------------
/user/leetcode/209.长度最小的子数组.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=209 lang=cpp
3 | *
4 | * [209] 长度最小的子数组
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int minSubArrayLen(int target, vector& nums) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/214.最短回文串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=214 lang=cpp
3 | *
4 | * [214] 最短回文串
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string shortestPalindrome(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/215.数组中的第k个最大元素.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=215 lang=cpp
3 | *
4 | * [215] 数组中的第K个最大元素
5 | */
6 | #include
7 | using namespace std;
8 |
9 | // @lc code=start
10 | class Solution {
11 | public:
12 | int findKthLargest(vector& nums, int k) {
13 | // 用小堆
14 | priority_queue, greater> q;
15 | for(auto v : nums){
16 | q.push(v);
17 | if(q.size()>k){
18 | q.pop();
19 | }
20 | }
21 | return q.top();
22 | }
23 | };
24 | // @lc code=end
25 |
26 |
--------------------------------------------------------------------------------
/user/leetcode/22.括号生成.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=22 lang=cpp
3 | *
4 | * [22] 括号生成
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector generateParenthesis(int n) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/220.存在重复元素-iii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=220 lang=cpp
3 | *
4 | * [220] 存在重复元素 III
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | using namespace std;
13 |
14 | // @lc code=start
15 | class Solution {
16 | public:
17 | bool containsNearbyAlmostDuplicate(vector& n, int k, int t)
18 | {
19 | set st;
20 | for (int i = 0; i < n.size(); i++) {
21 | // 找一个在区间n[i]-t到n[i]+t的数
22 | // 查找大于等于n[i]-t的值
23 | auto lb = st.lower_bound((long)n[i] - t);
24 | // 必须小于n[i]+t的值
25 | if (lb != st.end() && *lb <= (long)n[i] + t)
26 | return 1;
27 | // 滑动窗口大小为k
28 | st.insert(n[i]);
29 | if (i >= k)
30 | st.erase(n[i - k]);
31 | }
32 | return 0;
33 | }
34 | };
35 | // @lc code=end
36 |
--------------------------------------------------------------------------------
/user/leetcode/222.完全二叉树的节点个数.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=222 lang=cpp
3 | *
4 | * [222] 完全二叉树的节点个数
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int countNodes(TreeNode* root) {
22 | if (root == 0){
23 | return 0;
24 | }
25 | return countNodes(root->left) + countNodes(root->right) + 1;
26 | }
27 | };
28 | // @lc code=end
29 |
30 |
--------------------------------------------------------------------------------
/user/leetcode/225.用队列实现栈.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=225 lang=cpp
3 | *
4 | * [225] 用队列实现栈
5 | */
6 |
7 | // @lc code=start
8 | class MyStack {
9 | public:
10 | /** Initialize your data structure here. */
11 | MyStack() {
12 |
13 | }
14 |
15 | /** Push element x onto stack. */
16 | void push(int x) {
17 |
18 | }
19 |
20 | /** Removes the element on top of the stack and returns that element. */
21 | int pop() {
22 |
23 | }
24 |
25 | /** Get the top element. */
26 | int top() {
27 |
28 | }
29 |
30 | /** Returns whether the stack is empty. */
31 | bool empty() {
32 |
33 | }
34 | };
35 |
36 | /**
37 | * Your MyStack object will be instantiated and called as such:
38 | * MyStack* obj = new MyStack();
39 | * obj->push(x);
40 | * int param_2 = obj->pop();
41 | * int param_3 = obj->top();
42 | * bool param_4 = obj->empty();
43 | */
44 | // @lc code=end
45 |
46 |
--------------------------------------------------------------------------------
/user/leetcode/226.翻转二叉树.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=226 lang=cpp
3 | *
4 | * [226] 翻转二叉树
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | TreeNode* invertTree(TreeNode* root) {
22 | if(!root)return 0;
23 | auto t = root->left;
24 | root->left = root->right;
25 | root->right = t;
26 | invertTree(root->left);
27 | invertTree(root->right);
28 | return root;
29 | }
30 | };
31 | // @lc code=end
32 |
33 |
--------------------------------------------------------------------------------
/user/leetcode/227.基本计算器-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=227 lang=cpp
3 | *
4 | * [227] 基本计算器 II
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int calculate(string s) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/228.汇总区间.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=228 lang=cpp
3 | *
4 | * [228] 汇总区间
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector summaryRanges(vector& nums) {
11 | vector ret;
12 | int i = 0;
13 | int n = nums.size();
14 | while (i < n) {
15 | int low = i;
16 | i++;
17 | while (i < n && nums[i] == nums[i - 1] + 1) {
18 | i++;
19 | }
20 | int high = i - 1;
21 | string temp = to_string(nums[low]);
22 | if (low < high) {
23 | temp.append("->");
24 | temp.append(to_string(nums[high]));
25 | }
26 | ret.push_back(move(temp));
27 | }
28 | return ret;
29 | }
30 | };
31 | // @lc code=end
32 |
33 |
--------------------------------------------------------------------------------
/user/leetcode/230.二叉搜索树中第k小的元素.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=230 lang=cpp
3 | *
4 | * [230] 二叉搜索树中第K小的元素
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | int kthSmallest(TreeNode* root, int k) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/235.二叉搜索树的最近公共祖先.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=235 lang=cpp
3 | *
4 | * [235] 二叉搜索树的最近公共祖先
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 |
18 | class Solution {
19 | public:
20 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
21 | if(root->val < p->val && root->val < q->val)
22 | return lowestCommonAncestor(root->right, p, q);
23 | if(root->val > p->val && root->val > q->val)
24 | return lowestCommonAncestor(root->left, p, q);
25 | return root;
26 | }
27 | };
28 | // @lc code=end
29 |
30 |
--------------------------------------------------------------------------------
/user/leetcode/236.二叉树的最近公共祖先.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=236 lang=cpp
3 | *
4 | * [236] 二叉树的最近公共祖先
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
15 | * };
16 | */
17 | class Solution {
18 | public:
19 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
20 |
21 | }
22 | };
23 | // @lc code=end
24 |
25 |
--------------------------------------------------------------------------------
/user/leetcode/237. 删除链表中的节点.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=237 lang=cpp
3 | *
4 | * [237] 删除链表中的节点
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for singly-linked list.
10 | * struct ListNode {
11 | * int val;
12 | * ListNode *next;
13 | * ListNode(int x) : val(x), next(NULL) {}
14 | * };
15 | */
16 | class Solution {
17 | public:
18 | void deleteNode(ListNode* node) {
19 | node->val = node->next->val;
20 | node->next = node->next->next;
21 | }
22 | };
23 | // @lc code=end
--------------------------------------------------------------------------------
/user/leetcode/239.滑动窗口最大值.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=239 lang=cpp
3 | *
4 | * [239] 滑动窗口最大值
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | vector maxSlidingWindow(vector& nums, int k)
11 | {
12 | int n = nums.size();
13 | deque q;
14 | vector res;
15 | for (int i = 0; i < n; ++i) {
16 | while (!q.empty() && nums[i] >= nums[q.back()])
17 | q.pop_back();
18 | q.push_back(i);
19 | if (i - q.front() + 1 > k)
20 | q.pop_front();
21 | if (i >= k - 1)
22 | res.push_back(nums[q.front()]);
23 | }
24 | return res;
25 | }
26 | };
27 | // @lc code=end
28 |
--------------------------------------------------------------------------------
/user/leetcode/240.搜索二维矩阵-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=240 lang=cpp
3 | *
4 | * [240] 搜索二维矩阵 II
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | bool searchMatrix(vector>& matrix, int target) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/250.统计同值子树.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/acm-clan/algorithm-stone/926d57531d8db30a02cde7c0acae22e5dbe9c3a1/user/leetcode/250.统计同值子树.cpp
--------------------------------------------------------------------------------
/user/leetcode/257.二叉树的所有路径.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=257 lang=cpp
3 | *
4 | * [257] 二叉树的所有路径
5 | */
6 |
7 | // @lc code=start
8 | /**
9 | * Definition for a binary tree node.
10 | * struct TreeNode {
11 | * int val;
12 | * TreeNode *left;
13 | * TreeNode *right;
14 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
15 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17 | * };
18 | */
19 | class Solution {
20 | public:
21 | vector binaryTreePaths(TreeNode* root) {
22 |
23 | }
24 | };
25 | // @lc code=end
26 |
27 |
--------------------------------------------------------------------------------
/user/leetcode/264.丑数-ii.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=264 lang=cpp
3 | *
4 | * [264] 丑数 II
5 | */
6 |
7 | // 1, 2, 3, 4, 5, 6, 8, 9, 10, 12
8 | // @lc code=start
9 | class Solution {
10 | public:
11 | int nthUglyNumber(int n) {
12 | if(n == 0) return 0;
13 | int dp[n];
14 | int index2 = 0;
15 | int index3 = 0;
16 | int index5 = 0;
17 | dp[0] = 1;
18 | for(int i = 1; i < n; i++) {
19 | // 选择最小值,斐波拉契数列的变种
20 | dp[i] = min(dp[index2] * 2, min(dp[index3] * 3,dp[index5] * 5));
21 | if(dp[i] == dp[index2] * 2) index2++;
22 | if(dp[i] == dp[index3] * 3) index3++;
23 | if(dp[i] == dp[index5] * 5) index5++;
24 | }
25 | return dp[n - 1];
26 | }
27 | };
28 | // @lc code=end
29 |
30 |
--------------------------------------------------------------------------------
/user/leetcode/264.丑数-ii.md:
--------------------------------------------------------------------------------
1 | 斐波拉契数列的变种
2 |
3 | 数列的每一个值都会顺序乘以2、3、5,选择最小值递进
4 | f[i] = min(f[i2]*2, min(f[i3]*3, f[i5]*5))
5 |
6 |
7 |
--------------------------------------------------------------------------------
/user/leetcode/273.整数转换英文表示.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=273 lang=cpp
3 | *
4 | * [273] 整数转换英文表示
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | string numberToWords(int num) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/278.第一个错误的版本.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=278 lang=cpp
3 | *
4 | * [278] 第一个错误的版本
5 | */
6 |
7 | // @lc code=start
8 | // The API isBadVersion is defined for you.
9 | // bool isBadVersion(int version);
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | using namespace std;
16 |
17 | class Solution {
18 | public:
19 | int firstBadVersion(int n) {
20 | int64_t l=0, r=n;
21 | int64_t ans = n;
22 |
23 | while(l<=r){
24 | int64_t mid = (l+r)>>1;
25 | if(isBadVersion(mid)){
26 | ans = mid;
27 | r = mid - 1;
28 | }else{
29 | l = mid + 1;
30 | }
31 | }
32 | return ans;
33 | }
34 | };
35 | // @lc code=end
36 |
37 |
--------------------------------------------------------------------------------
/user/leetcode/28.实现-str-str.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=28 lang=cpp
3 | *
4 | * [28] 实现 strStr()
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int strStr(string haystack, string needle) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/29.两数相除.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=29 lang=cpp
3 | *
4 | * [29] 两数相除
5 | */
6 |
7 | // @lc code=start
8 | class Solution {
9 | public:
10 | int divide(int dividend, int divisor) {
11 |
12 | }
13 | };
14 | // @lc code=end
15 |
16 |
--------------------------------------------------------------------------------
/user/leetcode/3.无重复字符的最长子串.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * @lc app=leetcode.cn id=3 lang=cpp
3 | *
4 | * [3] 无重复字符的最长子串
5 | */
6 | #include
7 | #include