├── .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 | 4 | 5 | -------------------------------------------------------------------------------- /animations/storage/Tex/566ea9a4e08a514e.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /animations/storage/Tex/6efafd03c1284147.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /animations/storage/Tex/826b0ed5a45a92f4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /animations/storage/Tex/a2f8c7b9e4c1e831.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /animations/storage/Tex/a72defc9065a4a77.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /animations/storage/Tex/b1ff84f7b4a13e09.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /animations/storage/Tex/caec0844c39477d8.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /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 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | // @lc code=start 17 | class Solution { 18 | public: 19 | int lengthOfLongestSubstring(string s) 20 | { 21 | if (s.size() == 0) 22 | return 0; 23 | unordered_set hash; 24 | int m = 0; 25 | int left = 0; 26 | 27 | for (int i = 0; i < s.size(); i++) { 28 | // 存在就删除到存在的元素处 29 | while (hash.find(s[i]) != hash.end()) { 30 | hash.erase(s[left]); 31 | left++; 32 | } 33 | 34 | // 更新最长区间 35 | m = max(m, i - left + 1); 36 | // 插入新元素 37 | hash.insert(s[i]); 38 | } 39 | 40 | return m; 41 | } 42 | }; 43 | // @lc code=end 44 | -------------------------------------------------------------------------------- /user/leetcode/30.串联所有单词的子串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=30 lang=cpp 3 | * 4 | * [30] 串联所有单词的子串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector findSubstring(string s, vector& words) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/303.区域和检索-数组不可变.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=303 lang=cpp 3 | * 4 | * [303] 区域和检索 - 数组不可变 5 | */ 6 | #include 7 | using namespace std; 8 | 9 | // @lc code=start 10 | class NumArray { 11 | public: 12 | int f[10010]; 13 | NumArray(vector& nums) { 14 | // 让数组下标从1开始,便于处理偏移 15 | f[0] = 0; 16 | for(int i=0; isumRange(i,j); 30 | */ 31 | // @lc code=end 32 | 33 | -------------------------------------------------------------------------------- /user/leetcode/307.区域和检索-数组可修改.md: -------------------------------------------------------------------------------- 1 | ### 解题思路 2 | 3 | 这是一道很经典的题目,通常还能拓展出一大类问题。 4 | 5 | 针对不同的题目,我们有不同的方案可以选择(假设我们有一个数组): 6 | 7 | 1 数组不变,求区间和:「前缀和」、「树状数组」、「线段树」 8 | 9 | 2 多次修改某个数,求区间和:「树状数组」、「线段树」 10 | 11 | 3 多次整体修改某个区间,求区间和:「树状数组」、「线段树」 12 | 13 | 4 多次将某个区间变成同一个数,求区间和:「线段树」 14 | 15 | 这样看来,「线段树」能解决的问题是最多的,那我们是不是无论什么情况都写「线段树」呢? 16 | 17 | 答案并不是,而且恰好相反,只有在我们遇到第 4 类问题,不得不写「线段树」的时候,我们才考虑线段树。 18 | 19 | 因为「线段树」代码很长,而且常数很大,复杂度表现不算很好。我们只有在不得不用的时候才考虑「线段树」。 20 | 21 | 总结一下,我们应该按这样的优先级进行考虑: 22 | 23 | 简单求区间和,用「前缀和」 24 | 多次将某个区间变成同一个数,用「线段树」 25 | 其他情况:用「树状数组」 26 | 27 | ### 树状数组解法 28 | 本题显然属于第 2 类问题:多次修改某个数,求区间和。 29 | 30 | 我们使用「树状数组」进行求解。 31 | 32 | 而讲解「树状数组」和「线段树」极其复杂,如果要我用文字讲清楚的话,估计得上万字,不会有多少人愿意看。 33 | 34 | 因此我这里直接提供「树状数组」的代码,大家可以直接当做模板背过。 35 | 36 | 背过模板的意义在于,脑袋里有一个解决特定问题的 API 可以使用。 37 | -------------------------------------------------------------------------------- /user/leetcode/313.超级丑数.md: -------------------------------------------------------------------------------- 1 | 动态规划 超级简单 分析透彻 2 | 3 | ### 简单分析过程: 4 | 5 | 大家应该都做过丑数的题目。套路就是:为每个质因数建立一个指针,然后再这几个质因数运算的结果中,找出个最小的,然后匹配这个数是由哪个质因数算出来的,把它的指针值+1。 6 | 7 | 这道题的套路也差不多。只不过,因为我们这次是需要把计算出来的丑数再次和primes里面的质因数结合,算出新的丑数。算出来的丑数放在一个dp数组里。 8 | 9 | 所以,现在要做的事,怎么能知道每个质因数已经和dp中哪个位置的丑数进行了结合,下一个要结合的位置在哪。就需要建立一个index数组,用来存放每个质因数下一个将要结合的dp的下标,这个下标是从0开始的,每结合一次就+1。extra:有个细节我会在注释里写一下,就是如果出现不同的质因数相乘,乘出来的结果是相同的,是重复的丑数,这个时候该怎么办呢:应该把这几个质因数下一个要结合的dp下标都加1。因为只把其中一个+1的话,下一次计算的丑数一定会是刚才这个重复的丑数,你的结果中就会有很多重复的数,所以,全都加1的话就会把这个重复数给过滤掉了。 10 | 11 | 好了,现在就可以写代码了。 -------------------------------------------------------------------------------- /user/leetcode/315.计算右侧小于当前元素的个数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=315 lang=cpp 3 | * 4 | * [315] 计算右侧小于当前元素的个数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector countSmaller(vector& nums) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/316.去除重复字母.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=316 lang=cpp 3 | * 4 | * [316] 去除重复字母 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string removeDuplicateLetters(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/32.最长有效括号.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=32 lang=cpp 3 | * 4 | * [32] 最长有效括号 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int longestValidParentheses(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/33.搜索旋转排序数组.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=33 lang=cpp 3 | * 4 | * [33] 搜索旋转排序数组 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int search(vector& nums, int target) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/330.按要求补齐数组.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=330 lang=cpp 3 | * 4 | * [330] 按要求补齐数组 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minPatches(vector& nums, int n) { 11 | int patches = 0; 12 | long long x = 1; 13 | int length = nums.size(), index = 0; 14 | while (x <= n) { 15 | if (index < length && nums[index] <= x) { 16 | x += nums[index]; 17 | index++; 18 | } else { 19 | x <<= 1; 20 | patches++; 21 | } 22 | } 23 | return patches; 24 | } 25 | }; 26 | // @lc code=end 27 | 28 | -------------------------------------------------------------------------------- /user/leetcode/337.打家劫舍-iii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=337 lang=cpp 3 | * 4 | * [337] 打家劫舍 III 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 rob(TreeNode* root) { 20 | 21 | } 22 | }; 23 | // @lc code=end 24 | 25 | -------------------------------------------------------------------------------- /user/leetcode/344.反转字符串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=344 lang=cpp 3 | * 4 | * [344] 反转字符串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | void reverseString(vector& s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/349.两个数组的交集.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=349 lang=cpp 3 | * 4 | * [349] 两个数组的交集 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | // @lc code=start 14 | class Solution { 15 | public: 16 | vector intersection(vector& nums1, vector& nums2) { 17 | set s(nums1.begin(), nums1.end()); 18 | set ans; 19 | 20 | for(int j=0; j(ans.begin(), ans.end()); 27 | } 28 | }; 29 | // @lc code=end 30 | 31 | -------------------------------------------------------------------------------- /user/leetcode/350.两个数组的交集-ii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=350 lang=cpp 3 | * 4 | * [350] 两个数组的交集 II 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector intersect(vector& nums1, vector& nums2) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/357.计算各个位数不同的数字个数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=357 lang=cpp 3 | * 4 | * [357] 计算各个位数不同的数字个数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int countNumbersWithUniqueDigits(int n) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/367.有效的完全平方数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=367 lang=cpp 3 | * 4 | * [367] 有效的完全平方数 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | // @lc code=start 14 | class Solution { 15 | public: 16 | bool isPerfectSquare(int num) { 17 | int64_t l=0, r=num; 18 | int64_t ans=r; 19 | while(l<=r){ 20 | int64_t m = l + (r-l)/2; 21 | if(m*m >= num){ 22 | r = m-1; 23 | ans = m; 24 | }else{ 25 | l = m+1; 26 | } 27 | } 28 | printf("ans %d\n", ans); 29 | return ans*ans == num; 30 | } 31 | }; 32 | // @lc code=end 33 | 34 | -------------------------------------------------------------------------------- /user/leetcode/374.猜数字大小.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=374 lang=cpp 3 | * 4 | * [374] 猜数字大小 5 | */ 6 | 7 | // @lc code=start 8 | /** 9 | * Forward declaration of guess API. 10 | * @param num your guess 11 | * @return -1 if num is lower than the guess number 12 | * 1 if num is higher than the guess number 13 | * otherwise return 0 14 | * int guess(int num); 15 | */ 16 | 17 | class Solution { 18 | public: 19 | int guessNumber(int n) { 20 | 21 | } 22 | }; 23 | // @lc code=end 24 | 25 | -------------------------------------------------------------------------------- /user/leetcode/378.有序矩阵中第-k-小的元素.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=378 lang=cpp 3 | * 4 | * [378] 有序矩阵中第 K 小的元素 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int kthSmallest(vector>& matrix, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/38.外观数列.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=38 lang=cpp 3 | * 4 | * [38] 外观数列 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string countAndSay(int n) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/383.赎金信.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=383 lang=cpp 3 | * 4 | * [383] 赎金信 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool canConstruct(string ransomNote, string magazine) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/387.字符串中的第一个唯一字符.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=387 lang=cpp 3 | * 4 | * [387] 字符串中的第一个唯一字符 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int firstUniqChar(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/392.判断子序列.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=392 lang=cpp 3 | * 4 | * [392] 判断子序列 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool isSubsequence(string s, string t) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/392.判断子序列.py: -------------------------------------------------------------------------------- 1 | # 2 | # @lc app=leetcode.cn id=392 lang=python3 3 | # 4 | # [392] 判断子序列 5 | # 6 | 7 | # @lc code=start 8 | class Solution: 9 | def isSubsequence(self, s: str, t: str) -> bool: 10 | short, long = len(s), len(t) 11 | i = 0 12 | j = 0 13 | while (i& nums) { 11 | this->nums = nums; 12 | } 13 | 14 | int pick(int target) { 15 | int cnt = 0; 16 | int index = -1; 17 | for (int i = 0; i < nums.size(); i++) { 18 | if (nums[i] == target) { 19 | cnt++; 20 | if (rand() % cnt == 0) { 21 | index = i; // 1/i prob 22 | } 23 | } 24 | } 25 | 26 | return index; 27 | } 28 | 29 | private: 30 | vector nums; 31 | }; 32 | 33 | /** 34 | * Your Solution object will be instantiated and called as such: 35 | * Solution* obj = new Solution(nums); 36 | * int param_1 = obj->pick(target); 37 | */ 38 | // @lc code=end 39 | 40 | -------------------------------------------------------------------------------- /user/leetcode/399.除法求值.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=399 lang=cpp 3 | * 4 | * [399] 除法求值 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector calcEquation(vector>& equations, vector& values, vector>& queries) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/404.左叶子之和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=404 lang=cpp 3 | * 4 | * [404] 左叶子之和 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 sumOfLeftLeaves(TreeNode* root) { 20 | 21 | } 22 | }; 23 | // @lc code=end 24 | 25 | -------------------------------------------------------------------------------- /user/leetcode/407.接雨水-ii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=407 lang=cpp 3 | * 4 | * [407] 接雨水 II 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int trapRainWater(vector>& heightMap) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/413.等差数列划分.md: -------------------------------------------------------------------------------- 1 | 如下表 2 | 3 | | 数组 | 等差数列的数目 | 与上一数组的等差数列数目比较 | 4 | | ------------- | -------------- | ---------------------------- | 5 | | 1 2 3 | 1 | 1 - 0 = 1 | 6 | | 1 2 3 4 | 3 | 3 - 1 = 2 | 7 | | 1 2 3 4 5 | 6 | 6 - 3 = 3 | 8 | | 1 2 3 4 5 6 | 10 | 10 - 6 = 4 | 9 | | 1 2 3 4 5 6 7 | 15 | 15 - 10 = 5 | 10 | 11 | 观察就能发现两个等差数列数目之差(表格第三列)就是[1,2, 3, 4, 5……]这个序列,因此每次增加一个等差数列的元素,总的等差数列的数目就会增加[1,2, 3, 4, 5……]中对应的数值。 12 | 13 | DP思路: 14 | dp[i]表示以i位置的数为结尾中形成等差数列的个数的集合。则每次如果以A [ i ] 、 A [ i − 1 ] 、 A [ i − 2 ]形成一个等差数列,则这个A[i]有可能由和之前i-1位置为结尾形成的所有等差数列分别拼接而成,所以计算集合的值时要加上d p [ i − 1 ] 。最后统计所有结尾的等差数量sum即可。 15 | 16 | 17 | -------------------------------------------------------------------------------- /user/leetcode/415.字符串相加.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=415 lang=cpp 3 | * 4 | * [415] 字符串相加 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string addStrings(string num1, string num2) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/42.接雨水.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=42 lang=cpp 3 | * 4 | * [42] 接雨水 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int trap(vector& height) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/424.替换后的最长重复字符.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=424 lang=cpp 3 | * 4 | * [424] 替换后的最长重复字符 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int characterReplacement(string s, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/429.n-叉树的层序遍历.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=429 lang=cpp 3 | * 4 | * [429] N 叉树的层序遍历 5 | */ 6 | 7 | // @lc code=start 8 | /* 9 | // Definition for a Node. 10 | class Node { 11 | public: 12 | int val; 13 | vector children; 14 | 15 | Node() {} 16 | 17 | Node(int _val) { 18 | val = _val; 19 | } 20 | 21 | Node(int _val, vector _children) { 22 | val = _val; 23 | children = _children; 24 | } 25 | }; 26 | */ 27 | 28 | class Solution { 29 | public: 30 | vector> levelOrder(Node* root) { 31 | 32 | } 33 | }; 34 | // @lc code=end 35 | 36 | -------------------------------------------------------------------------------- /user/leetcode/43.字符串相乘.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=43 lang=cpp 3 | * 4 | * [43] 字符串相乘 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string multiply(string num1, string num2) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/430.扁平化多级双向链表.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | // Definition for a Node. 3 | class Node { 4 | public: 5 | int val; 6 | Node* prev; 7 | Node* next; 8 | Node* child; 9 | }; 10 | */ 11 | 12 | class Solution { 13 | public: 14 | Node* flatten(Node* head) { 15 | //if(head==nullptr) return head; 16 | 17 | Node*curr=head; 18 | while(curr){ 19 | if(curr->child){ 20 | Node*childlast=curr->child; 21 | while(childlast->next!=nullptr) childlast=childlast->next; 22 | 23 | curr->child->prev=curr; 24 | childlast->next=curr->next; 25 | if(curr->next) curr->next->prev=childlast; 26 | curr->next = curr->child; 27 | curr->child=nullptr; 28 | } 29 | curr=curr->next; 30 | } 31 | return head; 32 | } 33 | }; -------------------------------------------------------------------------------- /user/leetcode/434.字符串中的单词数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=434 lang=cpp 3 | * 4 | * [434] 字符串中的单词数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int countSegments(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/435.无重叠区间.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=435 lang=cpp 3 | * 4 | * [435] 无重叠区间 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int eraseOverlapIntervals(vector>& intervals) { 11 | sort(intervals.begin(),intervals.end(),[](vector& l,vector& r){return l[1]=left){ 17 | ++count; 18 | left=intervals[i][1]; 19 | } 20 | } 21 | return len-count; 22 | } 23 | }; 24 | 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/437.路径总和-iii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=437 lang=cpp 3 | * 4 | * [437] 路径总和 III 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 pathSum(TreeNode* root, int sum) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/44.通配符匹配.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=44 lang=cpp 3 | * 4 | * [44] 通配符匹配 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool isMatch(string s, string p) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/443.压缩字符串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=443 lang=cpp 3 | * 4 | * [443] 压缩字符串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int compress(vector& chars) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/448.找到所有数组中消失的数字.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=448 lang=cpp 3 | * 4 | * [448] 找到所有数组中消失的数字 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector findDisappearedNumbers(vector& nums) { 11 | int n = nums.size(); 12 | for (auto& num : nums) { 13 | int x = (num - 1) % n; 14 | nums[x] += n; 15 | } 16 | vector ret; 17 | for (int i = 0; i < n; i++) { 18 | if (nums[i] <= n) { 19 | ret.push_back(i + 1); 20 | } 21 | } 22 | return ret; 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/449.序列化和反序列化二叉搜索树.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=449 lang=cpp 3 | * 4 | * [449] 序列化和反序列化二叉搜索树 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 Codec { 18 | public: 19 | 20 | // Encodes a tree to a single string. 21 | string serialize(TreeNode* root) { 22 | 23 | } 24 | 25 | // Decodes your encoded data to tree. 26 | TreeNode* deserialize(string data) { 27 | 28 | } 29 | }; 30 | 31 | // Your Codec object will be instantiated and called as such: 32 | // Codec* ser = new Codec(); 33 | // Codec* deser = new Codec(); 34 | // string tree = ser->serialize(root); 35 | // TreeNode* ans = deser->deserialize(tree); 36 | // return ans; 37 | // @lc code=end 38 | 39 | -------------------------------------------------------------------------------- /user/leetcode/450.删除二叉搜索树中的节点.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=450 lang=cpp 3 | * 4 | * [450] 删除二叉搜索树中的节点 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* deleteNode(TreeNode* root, int key) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/455.分发饼干.py: -------------------------------------------------------------------------------- 1 | # 2 | # @lc app=leetcode.cn id=455 lang=python3 3 | # 4 | # [455] 分发饼干 5 | # 6 | 7 | # @lc code=start 8 | class Solution: 9 | def findContentChildren(self, g: List[int], s: List[int]) -> int: 10 | # @lc code=end 11 | 12 | -------------------------------------------------------------------------------- /user/leetcode/456.132-模式.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=456 lang=cpp 3 | * 4 | * [456] 132模式 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool find132pattern(vector& nums) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/459.重复的子字符串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=459 lang=cpp 3 | * 4 | * [459] 重复的子字符串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool repeatedSubstringPattern(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/470.用-rand-7-实现-rand-10.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=470 lang=cpp 3 | * 4 | * [470] 用 Rand7() 实现 Rand10() 5 | */ 6 | 7 | // @lc code=start 8 | // The rand7() API is already defined for you. 9 | // int rand7(); 10 | // @return a random integer in the range 1 to 7 11 | 12 | class Solution { 13 | public: 14 | int rand10() { 15 | int row, col, idx; 16 | do { 17 | row = rand7(); 18 | col = rand7(); 19 | idx = col + (row - 1) * 7; 20 | } while (idx > 40); 21 | return 1 + (idx - 1) % 10; 22 | } 23 | }; 24 | // @lc code=end 25 | 26 | -------------------------------------------------------------------------------- /user/leetcode/470.用-rand-7-实现-rand-10.md: -------------------------------------------------------------------------------- 1 | ### 题目大意 2 | 利用一个范围在1~7的随机数产生器,构造一个范围在1~10的随机数产生器。 3 | 4 | ### 解题方法 5 | 范围在1~7的随机数产生器,即1~7各个数字出现的概率皆为1/7. 6 | 范围在1~10的随机数产生器,即1~10各个数字出现的概率皆为1/10. 7 | 8 | 这个题的构造思路是先构造一个randN,这个N必须是10的整数倍,然后randN % 10就可以得到了rand10. 9 | 10 | 所以可以从rand7先构造出rand49,再把rand49中大于等于40的都过滤掉,这样就得到了rand40,在对10取余即可。 11 | 12 | 具体一点就是: 13 | 14 | rand7()等概率地产生1,2,3,4,5,6,7. 15 | rand7() - 1等概率地产生[0,6]. 16 | (rand7() - 1) *7等概率地产生0, 7, 14, 21, 28, 35, 42 17 | (rand7() - 1) * 7 + (rand7() - 1)等概率地产生[0, 48]这49个数字 18 | 如果步骤4的结果大于等于40,那么就重复步骤4,直到产生的数小于40 19 | 把步骤5的结果mod 10 再加1, 就会等概率的随机生成[1, 10] 20 | 21 | 所以过程是: 22 | rand7 --> rand49 --> rand40 --> rand10. 23 | -------------------------------------------------------------------------------- /user/leetcode/478.在圆内随机生成点.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=478 lang=cpp 3 | * 4 | * [478] 在圆内随机生成点 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | double r, x_cen, y_cen; 11 | Solution(double radius, double x_center, double y_center) { 12 | r = radius; 13 | x_cen = x_center; 14 | y_cen = y_center; 15 | } 16 | 17 | vector randPoint() { 18 | while (true) { 19 | double x = (2 * (double)rand() / RAND_MAX - 1.0) * r; 20 | double y = (2 * (double)rand() / RAND_MAX - 1.0) * r; 21 | if (x * x + y * y <= r * r) return {x_cen + x, y_cen + y}; 22 | } 23 | } 24 | }; 25 | 26 | /** 27 | * Your Solution object will be instantiated and called as such: 28 | * Solution* obj = new Solution(radius, x_center, y_center); 29 | * vector param_1 = obj->randPoint(); 30 | */ 31 | // @lc code=end 32 | 33 | -------------------------------------------------------------------------------- /user/leetcode/478.在圆内随机生成点.md: -------------------------------------------------------------------------------- 1 | 给定圆心和半径,让以uniform distribution生成落在圆内的随机点。用拒绝采样思想,随机在以圆心为心,2r为宽的正方形采样,对落在内切圆外的重采。在C++里(double)rand() / RAND_MAX表示随机生成[0,1.0)的浮点数,所以2 * (double)rand() / RAND_MAX表示[0, 2)的随机数生成器, 让它减去1即[-1, 1)的随机数生成器,再乘以r即[-r, r)的生成器。 -------------------------------------------------------------------------------- /user/leetcode/493.翻转对.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=493 lang=cpp 3 | * 4 | * [493] 翻转对 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int reversePairs(vector& nums) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/496.下一个更大元素-i.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=496 lang=cpp 3 | * 4 | * [496] 下一个更大元素 I 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector nextGreaterElement(vector& nums1, vector& nums2) { 11 | vector v; 12 | for(auto k : nums1){ 13 | int s = 0; 14 | int t = -1; 15 | for(auto j : nums2){ 16 | if(j==k){ 17 | s = 1; 18 | } 19 | if(s == 1 && j>k){ 20 | t = j; 21 | break; 22 | } 23 | } 24 | v.push_back(t); 25 | } 26 | return v; 27 | } 28 | }; 29 | // @lc code=end 30 | 31 | -------------------------------------------------------------------------------- /user/leetcode/5.最长回文子串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=5 lang=cpp 3 | * 4 | * [5] 最长回文子串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string longestPalindrome(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/502.ipo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=502 lang=cpp 3 | * 4 | * [502] IPO 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int findMaximizedCapital(int k, int W, vector& Profits, vector& Capital) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/508.出现次数最多的子树元素和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=508 lang=cpp 3 | * 4 | * [508] 出现次数最多的子树元素和 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 findFrequentTreeSum(TreeNode* root) { 20 | 21 | } 22 | }; 23 | // @lc code=end 24 | 25 | -------------------------------------------------------------------------------- /user/leetcode/509.斐波那契数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=509 lang=cpp 3 | * 4 | * [509] 斐波那契数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int fib(int n) { 11 | int f[n+10]; 12 | f[0] = 0; 13 | f[1] = 1; 14 | for(int i=2; i<=n; i++){ 15 | f[i] = f[i-1]+f[i-2]; 16 | } 17 | return f[n]; 18 | } 19 | }; 20 | // @lc code=end 21 | 22 | -------------------------------------------------------------------------------- /user/leetcode/513.找树左下角的值.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=513 lang=cpp 3 | * 4 | * [513] 找树左下角的值 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 findBottomLeftValue(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/520.检测大写字母.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=520 lang=cpp 3 | * 4 | * [520] 检测大写字母 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool detectCapitalUse(string word) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/521.最长特殊序列-ⅰ.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=521 lang=cpp 3 | * 4 | * [521] 最长特殊序列 Ⅰ 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int findLUSlength(string a, string b) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/53.最大子序和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=53 lang=cpp 3 | * 4 | * [53] 最大子序和 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int maxSubArray(vector& nums) { 11 | int n = nums.size(); 12 | int f[n]; 13 | f[0] = nums[0]; 14 | int m = f[0]; 15 | for(int i=1; i 0){ 19 | f[i] = f[i-1] + nums[i]; 20 | } 21 | // 记录最大值 22 | m = max(f[i], m); 23 | } 24 | return m; 25 | } 26 | }; 27 | // @lc code=end 28 | 29 | -------------------------------------------------------------------------------- /user/leetcode/53.最大子序和.md: -------------------------------------------------------------------------------- 1 | 从集合的角度考虑 2 | -------------------------------------------------------------------------------- /user/leetcode/530.二叉搜索树的最小绝对差.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=530 lang=cpp 3 | * 4 | * [530] 二叉搜索树的最小绝对差 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 | void travel(TreeNode * t){ 20 | if(!t)return; 21 | travel(t->left); 22 | // 23 | travel(t->right); 24 | } 25 | 26 | int getMinimumDifference(TreeNode* root) { 27 | 28 | } 29 | }; 30 | // @lc code=end 31 | 32 | -------------------------------------------------------------------------------- /user/leetcode/541.反转字符串-ii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=541 lang=cpp 3 | * 4 | * [541] 反转字符串 II 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string reverseStr(string s, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/543.二叉树的直径.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=543 lang=cpp 3 | * 4 | * [543] 二叉树的直径 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 res = 0; 20 | int dep(TreeNode* t){ 21 | if(!t)return 0; 22 | int l = dep(t->left); 23 | int r = dep(t->right); 24 | res = max(res, l+r); 25 | return max(l, r)+1; 26 | } 27 | int diameterOfBinaryTree(TreeNode* t) { 28 | dep(t); 29 | return res; 30 | } 31 | }; 32 | // @lc code=end 33 | 34 | -------------------------------------------------------------------------------- /user/leetcode/55.跳跃游戏.py: -------------------------------------------------------------------------------- 1 | # 2 | # @lc app=leetcode.cn id=55 lang=python3 3 | # 4 | # [55] 跳跃游戏 5 | # 6 | 7 | # @lc code=start 8 | class Solution: 9 | def canJump(self, nums: List[int]) -> bool: 10 | # @lc code=end 11 | 12 | -------------------------------------------------------------------------------- /user/leetcode/551.学生出勤记录-i.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=551 lang=cpp 3 | * 4 | * [551] 学生出勤记录 I 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool checkRecord(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/557.反转字符串中的单词-iii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=557 lang=cpp 3 | * 4 | * [557] 反转字符串中的单词 III 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string reverseWords(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/56.合并区间.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=56 lang=cpp 3 | * 4 | * [56] 合并区间 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector> merge(vector>& arr) { 11 | sort(arr.begin(),arr.end()); 12 | vector>ans; 13 | int start=arr[0][0]; 14 | int end=arr[0][1]; 15 | for(int i=1;ileft); 25 | int r = sum(t->right); 26 | res += abs(l-r); 27 | return l+r+t->val; 28 | } 29 | int findTilt(TreeNode* t) { 30 | sum(t); 31 | return res; 32 | } 33 | }; 34 | // @lc code=end 35 | 36 | -------------------------------------------------------------------------------- /user/leetcode/564.寻找最近的回文数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=564 lang=cpp 3 | * 4 | * [564] 寻找最近的回文数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string nearestPalindromic(string n) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/567.字符串的排列.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=567 lang=cpp 3 | * 4 | * [567] 字符串的排列 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool checkInclusion(string s1, string s2) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/576.出界的路径数.md: -------------------------------------------------------------------------------- 1 | ### 思路 2 | 这道题需要使用动态规划来做,但是要知道每个状态是怎么转移的。 3 | 4 | 对于一个起始点为i,j,N步可以走出的点的路径个数,等于该点周围的4个点,N-1步可以走出的路径个数之和,知道了这个之后,我们就可以以这个公式作为状态转移方程。 5 | 6 | f[i][j][N] = f[i-1][j][N-1]+f[i+1][j][N-1]+f[i][j-1][N-1]+f[i][j+1][N-1] 7 | 8 | 9 | -------------------------------------------------------------------------------- /user/leetcode/58.最后一个单词的长度.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=58 lang=cpp 3 | * 4 | * [58] 最后一个单词的长度 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int lengthOfLastWord(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/587.安装栅栏.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=587 lang=cpp 3 | * 4 | * [587] 安装栅栏 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector> outerTrees(vector>& points) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/591.标签验证器.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=591 lang=cpp 3 | * 4 | * [591] 标签验证器 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool isValid(string code) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/6.z-字形变换.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=6 lang=cpp 3 | * 4 | * [6] Z 字形变换 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string convert(string s, int numRows) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/605.种花问题.py: -------------------------------------------------------------------------------- 1 | # 2 | # @lc app=leetcode.cn id=605 lang=python3 3 | # 4 | # [605] 种花问题 5 | # 6 | 7 | # @lc code=start 8 | class Solution: 9 | def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: 10 | s = 1 11 | t = 0 12 | for k in flowerbed: 13 | if k == 1: 14 | if t == 1: 15 | n += 1 16 | t = 0 17 | s = 0 18 | else: 19 | t = 0 20 | s += 1 21 | if s == 2: 22 | t = 1 23 | n -= 1 24 | s = 0 25 | return n <= 0 26 | # @lc code=end 27 | -------------------------------------------------------------------------------- /user/leetcode/606.根据二叉树创建字符串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=606 lang=cpp 3 | * 4 | * [606] 根据二叉树创建字符串 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 | string s; 20 | void travel(TreeNode* t){ 21 | if(!t)return; 22 | s += std::to_string(t->val); 23 | 24 | if(t->left || t->right){ 25 | s+="("; 26 | travel(t->left); 27 | s += ")"; 28 | } 29 | 30 | if(t->right){ 31 | s+="("; 32 | travel(t->right); 33 | s += ")"; 34 | } 35 | } 36 | string tree2str(TreeNode* t) { 37 | travel(t); 38 | return s; 39 | } 40 | }; 41 | // @lc code=end 42 | 43 | -------------------------------------------------------------------------------- /user/leetcode/617.合并二叉树.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=617 lang=cpp 3 | * 4 | * [617] 合并二叉树 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* mergeTrees(TreeNode* root1, TreeNode* root2) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/62.不同路径.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=62 lang=cpp 3 | * 4 | * [62] 不同路径 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int uniquePaths(int m, int n) { 11 | int f[m][n]; 12 | f[0][0] = 1; 13 | for(int i=1; i>& g) { 11 | int m = g.size(); 12 | int n = g[0].size(); 13 | int f[m][n]; 14 | 15 | f[0][0] = g[0][0]?0:1; 16 | 17 | for(int i=1; i exclusiveTime(int n, vector& logs) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/64.最小路径和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=64 lang=cpp 3 | * 4 | * [64] 最小路径和 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | // f[i][j] = max(f[i-1][j], f[i][j-1]) 11 | int minPathSum(vector>& g) { 12 | int m = g.size(); 13 | int n = g[0].size(); 14 | int f[m][n]; 15 | f[0][0] = g[0][0]; 16 | for(int i=1; i> printTree(TreeNode* root) { 20 | 21 | } 22 | }; 23 | // @lc code=end 24 | 25 | -------------------------------------------------------------------------------- /user/leetcode/657.机器人能否返回原点.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=657 lang=cpp 3 | * 4 | * [657] 机器人能否返回原点 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool judgeCircle(string moves) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/662.二叉树最大宽度.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=662 lang=cpp 3 | * 4 | * [662] 二叉树最大宽度 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 widthOfBinaryTree(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/67.二进制求和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=67 lang=cpp 3 | * 4 | * [67] 二进制求和 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string addBinary(string a, string b) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/671.二叉树中第二小的节点.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=671 lang=cpp 3 | * 4 | * [671] 二叉树中第二小的节点 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 findSecondMinimumValue(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/676.实现一个魔法字典.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=676 lang=cpp 3 | * 4 | * [676] 实现一个魔法字典 5 | */ 6 | 7 | // @lc code=start 8 | class MagicDictionary { 9 | public: 10 | /** Initialize your data structure here. */ 11 | MagicDictionary() { 12 | 13 | } 14 | 15 | void buildDict(vector dictionary) { 16 | 17 | } 18 | 19 | bool search(string searchWord) { 20 | 21 | } 22 | }; 23 | 24 | /** 25 | * Your MagicDictionary object will be instantiated and called as such: 26 | * MagicDictionary* obj = new MagicDictionary(); 27 | * obj->buildDict(dictionary); 28 | * bool param_2 = obj->search(searchWord); 29 | */ 30 | // @lc code=end 31 | 32 | -------------------------------------------------------------------------------- /user/leetcode/677.键值映射.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=677 lang=cpp 3 | * 4 | * [677] 键值映射 5 | */ 6 | 7 | // @lc code=start 8 | class MapSum { 9 | public: 10 | /** Initialize your data structure here. */ 11 | MapSum() { 12 | 13 | } 14 | 15 | void insert(string key, int val) { 16 | 17 | } 18 | 19 | int sum(string prefix) { 20 | 21 | } 22 | }; 23 | 24 | /** 25 | * Your MapSum object will be instantiated and called as such: 26 | * MapSum* obj = new MapSum(); 27 | * obj->insert(key,val); 28 | * int param_2 = obj->sum(prefix); 29 | */ 30 | // @lc code=end 31 | 32 | -------------------------------------------------------------------------------- /user/leetcode/68.文本左右对齐.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=68 lang=cpp 3 | * 4 | * [68] 文本左右对齐 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector fullJustify(vector& words, int maxWidth) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/680.验证回文字符串-ⅱ.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=680 lang=cpp 3 | * 4 | * [680] 验证回文字符串 Ⅱ 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool validPalindrome(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/682.棒球比赛.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=682 lang=cpp 3 | * 4 | * [682] 棒球比赛 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int calPoints(vector& ops) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/684.冗余连接.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=684 lang=cpp 3 | * 4 | * [684] 冗余连接 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector findRedundantConnection(vector>& edges) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/689.三个无重叠子数组的最大和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=689 lang=cpp 3 | * 4 | * [689] 三个无重叠子数组的最大和 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector maxSumOfThreeSubarrays(vector& nums, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/69.x-的平方根.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=69 lang=cpp 3 | * 4 | * [69] x 的平方根 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | // @lc code=start 14 | class Solution { 15 | public: 16 | int mySqrt(int x) { 17 | int64_t l = 0, r = x; 18 | int64_t ans = 0; 19 | 20 | while(l<=r){ 21 | int64_t mid = l+(r-l)/2; 22 | if(mid*mid <= x){ 23 | ans = mid; 24 | l = mid+1; 25 | }else{ 26 | r = mid-1; 27 | } 28 | } 29 | return ans; 30 | } 31 | }; 32 | // @lc code=end 33 | 34 | -------------------------------------------------------------------------------- /user/leetcode/692.前k个高频单词.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=692 lang=cpp 3 | * 4 | * [692] 前K个高频单词 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector topKFrequent(vector& words, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/696.计数二进制子串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=696 lang=cpp 3 | * 4 | * [696] 计数二进制子串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int countBinarySubstrings(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/699.掉落的方块.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=699 lang=cpp 3 | * 4 | * [699] 掉落的方块 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector fallingSquares(vector>& positions) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/70.爬楼梯.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=70 lang=cpp 3 | * 4 | * [70] 爬楼梯 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int climbStairs(int n) { 11 | int f[n+1]; 12 | f[0] = 1; 13 | f[1] = 1; 14 | // 每次都有两种方式爬楼梯 15 | for(int i=2; i<=n; i++){ 16 | f[i] = f[i-1]+f[i-2]; 17 | } 18 | return f[n]; 19 | } 20 | }; 21 | // @lc code=end 22 | 23 | -------------------------------------------------------------------------------- /user/leetcode/700.二叉搜索树中的搜索.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=700 lang=cpp 3 | * 4 | * [700] 二叉搜索树中的搜索 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* searchBST(TreeNode* root, int val) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/703.数据流中的第-k-大元素.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=703 lang=cpp 3 | * 4 | * [703] 数据流中的第 K 大元素 5 | */ 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | // @lc code=start 11 | class KthLargest { 12 | public: 13 | priority_queue, greater> q; 14 | int k; 15 | KthLargest(int k, vector& nums) { 16 | this->k = k; 17 | for (auto& x: nums) { 18 | add(x); 19 | } 20 | } 21 | 22 | int add(int val) { 23 | q.push(val); 24 | if (q.size() > k) { 25 | q.pop(); 26 | } 27 | return q.top(); 28 | } 29 | }; 30 | 31 | /** 32 | * Your KthLargest object will be instantiated and called as such: 33 | * KthLargest* obj = new KthLargest(k, nums); 34 | * int param_1 = obj->add(val); 35 | */ 36 | // @lc code=end 37 | 38 | -------------------------------------------------------------------------------- /user/leetcode/704.二分查找.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=704 lang=cpp 3 | * 4 | * [704] 二分查找 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | // @lc code=start 14 | class Solution { 15 | public: 16 | int search(vector& nums, int t) { 17 | int n = nums.size(); 18 | int l=0, r = n-1; 19 | 20 | while(l<=r){ 21 | int m = l+r>>1; 22 | if(t == nums[m]){ 23 | return m; 24 | }else if (t < nums[m]){ 25 | r = m-1; 26 | }else{ 27 | l = m+1; 28 | } 29 | } 30 | return -1; 31 | } 32 | }; 33 | // @lc code=end 34 | 35 | -------------------------------------------------------------------------------- /user/leetcode/71.简化路径.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=71 lang=cpp 3 | * 4 | * [71] 简化路径 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string simplifyPath(string path) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/715.range-模块.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=715 lang=cpp 3 | * 4 | * [715] Range 模块 5 | */ 6 | 7 | // @lc code=start 8 | class RangeModule { 9 | public: 10 | RangeModule() { 11 | 12 | } 13 | 14 | void addRange(int left, int right) { 15 | 16 | } 17 | 18 | bool queryRange(int left, int right) { 19 | 20 | } 21 | 22 | void removeRange(int left, int right) { 23 | 24 | } 25 | }; 26 | 27 | /** 28 | * Your RangeModule object will be instantiated and called as such: 29 | * RangeModule* obj = new RangeModule(); 30 | * obj->addRange(left,right); 31 | * bool param_2 = obj->queryRange(left,right); 32 | * obj->removeRange(left,right); 33 | */ 34 | // @lc code=end 35 | 36 | -------------------------------------------------------------------------------- /user/leetcode/719.找出第-k-小的距离对.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=719 lang=cpp 3 | * 4 | * [719] 找出第 k 小的距离对 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int smallestDistancePair(vector& nums, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/72.编辑距离.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=72 lang=cpp 3 | * 4 | * [72] 编辑距离 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minDistance(string word1, string word2) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/721.账户合并.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=721 lang=cpp 3 | * 4 | * [721] 账户合并 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector> accountsMerge(vector>& accounts) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/726.原子的数量.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=726 lang=cpp 3 | * 4 | * [726] 原子的数量 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string countOfAtoms(string formula) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/735.行星碰撞.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=735 lang=cpp 3 | * 4 | * [735] 行星碰撞 5 | */ 6 | #include 7 | using namespace std; 8 | 9 | // @lc code=start 10 | class Solution { 11 | public: 12 | vector asteroidCollision(vector& asteroids) 13 | { 14 | vector ans; 15 | int n = asteroids.size(); 16 | for (int i = 0; i < n; ++i) { 17 | if (ans.empty() || asteroids[i] > 0) { 18 | ans.push_back(asteroids[i]); 19 | } else { 20 | while (ans.size() && ans.back() > 0 && ans.back() < -asteroids[i]) 21 | ans.pop_back(); 22 | if (ans.empty() || ans.back() < 0) 23 | ans.push_back(asteroids[i]); 24 | else if (ans.back() == -asteroids[i]) 25 | ans.pop_back(); 26 | } 27 | } 28 | return ans; 29 | } 30 | }; 31 | // @lc code=end 32 | -------------------------------------------------------------------------------- /user/leetcode/736.lisp-语法解析.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=736 lang=cpp 3 | * 4 | * [736] Lisp 语法解析 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int evaluate(string expression) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/743.网络延迟时间.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=743 lang=cpp 3 | * 4 | * [743] 网络延迟时间 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int networkDelayTime(vector>& times, int n, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/746.使用最小花费爬楼梯.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=746 lang=cpp 3 | * 4 | * [746] 使用最小花费爬楼梯 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minCostClimbingStairs(vector& cost) { 11 | int n = cost.size(); 12 | int f[n]; 13 | f[0] = cost[0]; 14 | f[1] = cost[1]; 15 | for(int i=2; i basicCalculatorIV(string expression, vector& evalvars, vector& evalints) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/778.水位上升的泳池中游泳.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=778 lang=cpp 3 | * 4 | * [778] 水位上升的泳池中游泳 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int swimInWater(vector>& grid) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/783.二叉搜索树节点最小距离.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=783 lang=cpp 3 | * 4 | * [783] 二叉搜索树节点最小距离 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 minDiffInBST(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/786.第-k-个最小的素数分数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=786 lang=cpp 3 | * 4 | * [786] 第 K 个最小的素数分数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector kthSmallestPrimeFraction(vector& arr, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/787.k-站中转内最便宜的航班.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=787 lang=cpp 3 | * 4 | * [787] K 站中转内最便宜的航班 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int findCheapestPrice(int n, vector>& flights, int src, int dst, int K) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/790.多米诺和托米诺平铺.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=790 lang=cpp 3 | * 4 | * [790] 多米诺和托米诺平铺 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int numTilings(int N) { 11 | long long f[N+1][2]; 12 | memset(f, 0, sizeof(f)); 13 | f[0][0] = 1; 14 | f[1][0] = 1; 15 | f[1][1] = 2; 16 | long long m = 1e9+7; 17 | for(int i=2; i<=N; i++){ 18 | // f[i - 1][0]是竖着放一块 19 | // f[i - 2][0]只可能是2块横着放 20 | // f[i - 1][1]只可能固定一种结果 21 | f[i][0] = (f[i - 1][0] + f[i - 2][0] + f[i - 2][1]) % m; 22 | 23 | //f[i][1]表示有一个脚在i+1列,f[i - 1][0]上下放一个横板,f[i - 1][1]放一个横板 24 | f[i][1] = (f[i - 1][0]*2 + f[i - 1][1]) % m; 25 | } 26 | return f[N][0]; 27 | } 28 | }; 29 | // @lc code=end 30 | 31 | -------------------------------------------------------------------------------- /user/leetcode/790.多米诺和托米诺平铺.md: -------------------------------------------------------------------------------- 1 | ### 从[Leetcode 790. Domino and Tromino Tiling]谈DP 2 | https://www.jianshu.com/p/2104df9de5d5 3 | 4 | ### 夜深人静写算法(二) - 动态规划 5 | https://www.open-open.com/lib/view/open1450603787347.html 6 | 7 | -------------------------------------------------------------------------------- /user/leetcode/8.字符串转换整数-atoi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=8 lang=cpp 3 | * 4 | * [8] 字符串转换整数 (atoi) 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int myAtoi(string s) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/817. 链表组件.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=817 lang=cpp 3 | * 4 | * [817] 链表组件 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 | // 唯一值,链表的值是否在G中,使用set判断 19 | int numComponents(ListNode* head, vector& G) { 20 | unordered_setnums(G.begin(),G.end()); 21 | int cnt=0; 22 | ListNode*curr=head; 23 | while(curr){ 24 | if(nums.count(curr->val)){ 25 | cnt+=1; 26 | while(curr &&nums.count(curr->val)){curr=curr->next;} 27 | }else{curr=curr->next;} 28 | } 29 | return cnt; 30 | } 31 | }; 32 | // @lc code=end -------------------------------------------------------------------------------- /user/leetcode/818.赛车.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=818 lang=cpp 3 | * 4 | * [818] 赛车 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int racecar(int target) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/82. 删除排序链表中的重复元素 II.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=82 lang=cpp 3 | * 4 | * [82] 删除排序链表中的重复元素 II 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* deleteDuplicates(ListNode* head) { 21 | if(head==nullptr || head->next==nullptr) return head; 22 | 23 | if(head->val!=head->next->val) head->next=deleteDuplicates(head->next); 24 | else{ 25 | while(head->next && head->val==head->next->val){ 26 | head->next =head->next->next; 27 | } 28 | return deleteDuplicates(head->next); 29 | } 30 | return head; 31 | } 32 | }; 33 | // @lc code=end -------------------------------------------------------------------------------- /user/leetcode/83.删除排序链表中重复的元素.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=83 lang=cpp 3 | * 4 | * [83] 删除排序链表中重复的元素 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* deleteDuplicates(ListNode* head) { 21 | if(head==nullptr || head->next==nullptr) return head; 22 | 23 | ListNode*ne =deleteDuplicates(head->next); 24 | if(head->val == ne->val){head->next = ne->next;} 25 | return head; 26 | } 27 | }; 28 | // @lc code=end -------------------------------------------------------------------------------- /user/leetcode/84.柱状图中最大的矩形.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=84 lang=cpp 3 | * 4 | * [84] 柱状图中最大的矩形 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int largestRectangleArea(vector& heights) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/846.一手顺子.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=846 lang=cpp 3 | * 4 | * [846] 一手顺子 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool isNStraightHand(vector& hand, int W) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/85.最大矩形.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=85 lang=cpp 3 | * 4 | * [85] 最大矩形 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int maximalRectangle(vector>& matrix) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/850.矩形面积-ii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=850 lang=cpp 3 | * 4 | * [850] 矩形面积 II 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int rectangleArea(vector>& rectangles) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/856.括号的分数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=856 lang=cpp 3 | * 4 | * [856] 括号的分数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int scoreOfParentheses(string S) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/857.雇佣-k-名工人的最低成本.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=857 lang=cpp 3 | * 4 | * [857] 雇佣 K 名工人的最低成本 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | double mincostToHireWorkers(vector& quality, vector& wage, int K) 11 | { 12 | vector> x; 13 | int N = quality.size(); 14 | for (int i = 0; i < N; i++) 15 | x.push_back({ wage[i] * 1.0 / quality[i] * 1.0, quality[i] }); 16 | sort(x.begin(), x.end()); 17 | double res = INT_MAX, temp = 0.0; 18 | priority_queue heap; 19 | for (auto worker : x) { 20 | heap.push(worker.second); 21 | temp += worker.second; 22 | if (heap.size() > K) { 23 | temp -= heap.top(); 24 | heap.pop(); 25 | } 26 | if (heap.size() == K) 27 | res = min(res, temp * worker.first); 28 | } 29 | return res; 30 | } 31 | }; 32 | // @lc code=end 33 | -------------------------------------------------------------------------------- /user/leetcode/860.柠檬水找零.py: -------------------------------------------------------------------------------- 1 | # 2 | # @lc app=leetcode.cn id=860 lang=python3 3 | # 4 | # [860] 柠檬水找零 5 | # 6 | 7 | # @lc code=start 8 | class Solution: 9 | def lemonadeChange(self, bills: List[int]) -> bool: 10 | 11 | # @lc code=end 12 | 13 | -------------------------------------------------------------------------------- /user/leetcode/864.获取所有钥匙的最短路径.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=864 lang=cpp 3 | * 4 | * [864] 获取所有钥匙的最短路径 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int shortestPathAllKeys(vector& grid) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/87.扰乱字符串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=87 lang=cpp 3 | * 4 | * [87] 扰乱字符串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool isScramble(string s1, string s2) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/871.最低加油次数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=871 lang=cpp 3 | * 4 | * [871] 最低加油次数 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minRefuelStops(int target, int startFuel, vector>& stations) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/876. 链表的中间结点.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @lc app=leetcode.cn id=876 lang=cpp 4 | * 5 | * [876] 链表的中间结点 6 | */ 7 | 8 | // @lc code=start 9 | /** 10 | * Definition for singly-linked list. 11 | * struct ListNode { 12 | * int val; 13 | * ListNode *next; 14 | * ListNode(int x) : val(x), next(NULL) {} 15 | * }; 16 | */ 17 | class Solution { 18 | public: 19 | ListNode* middleNode(ListNode* head) { 20 | //if(head==nulptr || head->next==nullptr) return head; 去除特殊情况 21 | 22 | //两个指针都从哨兵开始,避免slow=head,fast=head->next初始化时就是nullptr 23 | ListNode*sentry=new ListNode(0,head); 24 | ListNode*slow=sentry,*fast=sentry; 25 | 26 | while(fast!=nullptr){ 27 | slow=slow->next; 28 | fast=fast->next; 29 | if(fast) fast=fast->next; 30 | } 31 | return slow; 32 | } 33 | }; 34 | // @lc code=end 35 | -------------------------------------------------------------------------------- /user/leetcode/880.索引处的解码字符串.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=880 lang=cpp 3 | * 4 | * [880] 索引处的解码字符串 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string decodeAtIndex(string S, int K) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/882.细分图中的可到达结点.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=882 lang=cpp 3 | * 4 | * [882] 细分图中的可到达结点 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int reachableNodes(vector>& edges, int maxMoves, int n) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/892.三维形体的表面积.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=892 lang=cpp 3 | * 4 | * [892] 三维形体的表面积 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int surfaceArea(vector>& grid) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/895.最大频率栈.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=895 lang=cpp 3 | * 4 | * [895] 最大频率栈 5 | */ 6 | 7 | // @lc code=start 8 | class FreqStack { 9 | public: 10 | FreqStack() { 11 | 12 | } 13 | 14 | void push(int val) { 15 | 16 | } 17 | 18 | int pop() { 19 | 20 | } 21 | }; 22 | 23 | /** 24 | * Your FreqStack object will be instantiated and called as such: 25 | * FreqStack* obj = new FreqStack(); 26 | * obj->push(val); 27 | * int param_2 = obj->pop(); 28 | */ 29 | // @lc code=end 30 | 31 | -------------------------------------------------------------------------------- /user/leetcode/899.有序队列.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=899 lang=cpp 3 | * 4 | * [899] 有序队列 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | string orderlyQueue(string s, int k) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/901.股票价格跨度.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=901 lang=cpp 3 | * 4 | * [901] 股票价格跨度 5 | */ 6 | 7 | // @lc code=start 8 | class StockSpanner { 9 | public: 10 | StockSpanner() { 11 | 12 | } 13 | 14 | int next(int price) { 15 | 16 | } 17 | }; 18 | 19 | /** 20 | * Your StockSpanner object will be instantiated and called as such: 21 | * StockSpanner* obj = new StockSpanner(); 22 | * int param_1 = obj->next(price); 23 | */ 24 | // @lc code=end 25 | 26 | -------------------------------------------------------------------------------- /user/leetcode/907.子数组的最小值之和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=907 lang=cpp 3 | * 4 | * [907] 子数组的最小值之和 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int sumSubarrayMins(vector& arr) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/91.解码方法.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=91 lang=cpp 3 | * 1210340156 4 | * 5 | * [91] 解码方法 6 | */ 7 | #include 8 | using namespace std; 9 | 10 | // @lc code=start 11 | class Solution { 12 | public: 13 | int numDecodings(string s) { 14 | int n = s.length(); 15 | if(n == 0) return 0; 16 | int f[n+1]; 17 | f[0] = 1; 18 | f[1] = s[0] == '0'?0:1; 19 | // 思路很简单,一个数字直接加,2个数字判断是不是10到26 20 | for(int i=2; i<=n; i++){ 21 | // single 22 | if(s[i-1] != '0'){ 23 | f[i] = f[i-1]; 24 | } 25 | // double 26 | int two = (s[i-2]-'0')*10 + s[i-1]-'0'; 27 | if(two >= 10 && two <= 26){ 28 | f[i] += f[i-2]; 29 | } 30 | } 31 | return f[n]; 32 | } 33 | }; 34 | // @lc code=end 35 | 36 | -------------------------------------------------------------------------------- /user/leetcode/91.解码方法.md: -------------------------------------------------------------------------------- 1 | 思路很简单,一个数字直接加,2个数字判断是不是10到26 2 | 3 | -------------------------------------------------------------------------------- /user/leetcode/921.使括号有效的最少添加.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=921 lang=cpp 3 | * 4 | * [921] 使括号有效的最少添加 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minAddToMakeValid(string S) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/931.下降路径最小和.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=931 lang=cpp 3 | * 4 | * [931] 下降路径最小和 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minFallingPathSum(vector>& g) { 11 | int n=g.size(); 12 | int f[n][n]; 13 | int m = INT_MAX; 14 | for(int j=0; j= n?(n-1):(j+1); 23 | int k = g[i][j]; 24 | f[i][j] = min(min(f[i-1][l],f[i-1][c]), f[i-1][r])+k; 25 | //printf("f[%d][%d]=%d\n", i, j, f[i][j]); 26 | } 27 | } 28 | for(int j=0; j beautifulArray(int n) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/933.最近的请求次数.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=933 lang=cpp 3 | * 4 | * [933] 最近的请求次数 5 | */ 6 | #include 7 | using namespace std; 8 | 9 | // @lc code=start 10 | class RecentCounter { 11 | public: 12 | queue q; 13 | RecentCounter() { 14 | 15 | } 16 | 17 | int ping(int t) { 18 | q.push(t); 19 | // 取出超过3000的数值,只保留3000以内的 20 | while(q.front() < t-3000){ 21 | q.pop(); 22 | } 23 | return q.size(); 24 | } 25 | }; 26 | 27 | /** 28 | * Your RecentCounter object will be instantiated and called as such: 29 | * RecentCounter* obj = new RecentCounter(); 30 | * int param_1 = obj->ping(t); 31 | */ 32 | // @lc code=end 33 | 34 | -------------------------------------------------------------------------------- /user/leetcode/935.骑士拨号器.md: -------------------------------------------------------------------------------- 1 | ### 题解 2 | 每个格子可以跳到的下一步是有限的。所以从某个格子跳n步就可以化作从该格子能跳到的格子开始跳n-1步的子问题。很明显用动态规划,并且也挺好写。 3 | 4 | 注意N大于等于2时放在5那里无法移动。 -------------------------------------------------------------------------------- /user/leetcode/936.戳印序列.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=936 lang=cpp 3 | * 4 | * [936] 戳印序列 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | vector movesToStamp(string stamp, string target) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/94.二叉树的中序遍历.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=94 lang=cpp 3 | * 4 | * [94] 二叉树的中序遍历 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 | void travel(TreeNode* t, vector & v){ 22 | if(!t)return; 23 | travel(t->left, v); 24 | // 25 | v.push_back(t->val); 26 | travel(t->right, v); 27 | } 28 | vector inorderTraversal(TreeNode* t) { 29 | vector v; 30 | travel(t, v); 31 | return v; 32 | } 33 | }; 34 | // @lc code=end 35 | 36 | -------------------------------------------------------------------------------- /user/leetcode/944.删列造序.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=944 lang=cpp 3 | * 4 | * [944] 删列造序 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int minDeletionSize(vector& strs) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/946.验证栈序列.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=946 lang=cpp 3 | * 4 | * [946] 验证栈序列 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | bool validateStackSequences(vector& pushed, vector& popped) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/95.不同的二叉搜索树-ii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=95 lang=cpp 3 | * 4 | * [95] 不同的二叉搜索树 II 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 generateTrees(int n) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/96.不同的二叉搜索树.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=96 lang=cpp 3 | * 4 | * [96] 不同的二叉搜索树 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int numTrees(int n) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/963.最小面积矩形-ii.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=963 lang=cpp 3 | * 4 | * [963] 最小面积矩形 II 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | double minAreaFreeRect(vector>& points) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/968.监控二叉树.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=968 lang=cpp 3 | * 4 | * [968] 监控二叉树 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 minCameraCover(TreeNode* root) { 20 | 21 | } 22 | }; 23 | // @lc code=end 24 | 25 | -------------------------------------------------------------------------------- /user/leetcode/975.奇偶跳.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=975 lang=cpp 3 | * 4 | * [975] 奇偶跳 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int oddEvenJumps(vector& arr) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/978.最长湍流子数组.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=978 lang=cpp 3 | * 4 | * [978] 最长湍流子数组 5 | */ 6 | 7 | // @lc code=start 8 | class Solution { 9 | public: 10 | int maxTurbulenceSize(vector& arr) { 11 | 12 | } 13 | }; 14 | // @lc code=end 15 | 16 | -------------------------------------------------------------------------------- /user/leetcode/98.验证二叉搜索树.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=98 lang=cpp 3 | * 4 | * [98] 验证二叉搜索树 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 isValidBST(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/981.基于时间的键值存储.py: -------------------------------------------------------------------------------- 1 | # 2 | # @lc app=leetcode.cn id=981 lang=python3 3 | # 4 | # [981] 基于时间的键值存储 5 | # 6 | 7 | # @lc code=start 8 | class TimeMap(object): 9 | def __init__(self): 10 | self.M = collections.defaultdict(list) 11 | 12 | def set(self, key, value, timestamp): 13 | self.M[key].append((timestamp, value)) 14 | 15 | def get(self, key, timestamp): 16 | A = self.M.get(key, None) 17 | if A is None: return "" 18 | i = bisect.bisect(A, (timestamp, chr(127))) 19 | return A[i-1][1] if i else "" 20 | 21 | # Your TimeMap object will be instantiated and called as such: 22 | # obj = TimeMap() 23 | # obj.set(key,value,timestamp) 24 | # param_2 = obj.get(key,timestamp) 25 | # @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/987.二叉树的垂序遍历.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=987 lang=cpp 3 | * 4 | * [987] 二叉树的垂序遍历 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> verticalTraversal(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | -------------------------------------------------------------------------------- /user/leetcode/99.恢复二叉搜索树.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @lc app=leetcode.cn id=99 lang=cpp 3 | * 4 | * [99] 恢复二叉搜索树 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 | void recoverTree(TreeNode* root) { 22 | 23 | } 24 | }; 25 | // @lc code=end 26 | 27 | --------------------------------------------------------------------------------