Leetcode catalogue
1. Array & List
1.1Sort
Array的变更操作,好好运用尾指针:88题的end,75题的blueHead
- 88. Merge Sorted Array (Array)
- 75. Sort Colors
- 21. Merge Two Sorted Lists
- 23. Merge k Sorted Lists
- 128. Longest Consecutive Sequence
- 147. Insertion Sort List
- 148. Sort List
1.2 Rejust List
两种方法:
法I:改变结构
涉及的操作主要有:
- 子队列中逆序
- 子队列与前队列连接
- 子队列与后队列连接
在赋值的时候前后顺序是有讲究的,先备份到tmp,然后再给它赋值
法II: 只改变值,如:Delete a node in the middle of a single linked list, fiven only access to that node. -->Solution: 把下一个节点赋值给该节点,删除下一个节点,这样就省却了寻找上一个节点的麻烦。
注意特殊节点:(以防空指针)
- NULL
- head
- tail
比如上题
if(n==null || n->next == null) return false;
ListNode* next = n->next;
n->data = next->data;
n->next = next->next;
- 86. Partition List
- 92. Reverse Linked List II
- 61. Rotate List
- 25. Reverse Nodes in k-Group
- 24. Swap Nodes in Pairs
- 143. Reorder List
- 27. Remove Element
- 26. Remove Duplicates from Sorted Array
- 80. Remove Duplicates from Sorted Array II
- 83. Remove Duplicates from Sorted List
- 82. Remove Duplicates from Sorted List II
1.3 Search sorted array
- 35. Search Insert Position
- 34. Search for a Range
- 108.Convert Sorted Array to Binary Search Tree
- 109. Convert Sorted List to Binary Search Tree
- 69. Sqrt(x)
- 4.Median of Two Sorted Arrays
- 167. Two Sum II - Input array is sorted (Array)
1.4 Search unsorted array
- 135. Candy
- 31. Next Permutation
- 发帖水王 <编程之美> P130
1.5 Two Pointers
- 15. 3Sum
- 16. 3Sum Closest
- 125. Valid Palindrome
- 11.Container With Most Water
- 19. Remove Nth Node From End of List
- 141. Linked List Cycle
- 142. Linked List Cycle II
1.6 双向链表
- 146. LRU Cache
1.7 Shift
- 通过逆序移位 <编程之美> P201
- 字符串通过连接来代替移位 P103
2. Stack & Queue
2.1 Queue
- 三个队列排序 p195
- 实现带最大值查询的队列 <编程之美> P239
2.2Stack
- 114. Flatten Binary Tree to Linked List
- 144. Binary Tree Preorder Traversal
- 145. Binary Tree Postorder Traversal
- 71. Simplify Path
- 20. Valid Parentheses
- 32. Longest Valid Parentheses
- 150. Evaluate Reverse Polish Notation
- 84. Largest Rectangle in Histogram
- 85. Maximal Rectangle
- Implementation Stack by Array p111
- stack的实现(含min方法)p113
- Hanoi p118
3. Tree
前序遍历(Pre-order Traversal):自己->左->右
- 前序遍历用于,从上到下的遍历,左右子数的遍历依赖于根节点的数据
中序遍历(In-order Traversal):左->自己->右
前序遍历(Post-order Traversal):左->右->自己
- 后序遍历用于,从下到上的遍历,根节点的处理依赖于左右子数的遍历结果
3.1 递归实现前序遍历
- 112. Path Sum
- 113. Path Sum II
- 129. Sum Root to Leaf Numbers
3.2 递归实现中序遍历
- 99. Recover Binary Search Tree
3.3 递归实现后序遍历
- 124. Binary Tree Maximum Path Sum
- 111. Minimum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 110. Balanced Binary Tree
- 96. Unique Binary Search Trees
- 95. Unique Binary Search Trees II
- 101. Symmetric Tree
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
3.4“循环+栈”实现前序、中序、后序
- 114. Flatten Binary Tree to Linked List(2.2)
- 144. Binary Tree Preorder Traversal(2.2)
- 145. Binary Tree Postorder Traversal(2.2)
3.5 level search(wfs)
树是一种特殊的图,在树中,广度优先搜索又称为层次搜索;深度有限搜索又分为前序、中序、后序
- 107. Binary Tree Level Order Traversal II
- 116. Populating Next Right Pointers in Each Node
- 117. Populating Next Right Pointers in Each Node II
- 127. Word Ladder
4. Graph
注意:对于不能重复遍历的情况,需要为每个节点标记是否已访问过。
4.1 遍历所有节点,两个for循环
- 118. Pascal's Triangle
- 119. Pascal's Triangle II
- 120. Triangle
- 48. Rotate Image
- 74. Search a 2D Matrix
- 36. Valid Sudoku
4.2 设定遍历方向,按照该方向遍历
- 54. Spiral Matrix
- 59. Spiral Matrix II
4.3 DFS
- 79. Word Search
- 73. Set Matrix Zeroes
- 133. Clone Graph
- 138. Copy List with Random Pointer
- 130. Surrounded Regions
4.4 WFS
- 126. Word Ladder II (unordered_map,map,set的使用)
4.5 Dynamic Programming
- 64. Minimum Path Sum
- 62. Unique Paths(为什么DP优于DFS)
- 63. Unique Paths II
4.6 数据结构
- bfs在大数据时通过hash表代替node marking p199
- 稀疏矩阵的表示方法(链表、数组、三元组) <珠玑>p97 p209
4.7 着色问题
- 点图&区间图 <编程之美> P58-60
5. Hash table, map
- 1. Two Sum
- 3. Longest Substring Without Repeating Characters (KMP)
- 76. Minimum Window Substring
- 49. Group Anagrams
- 30. Substring with Concatenation of All Words
- 41. First Missing Positive
- 18. 4Sum (Hash table时间复杂度)
6. recursion
递归剪枝:
法I:最优剪枝。如果目前的结果已经差于之前得到的最优值,那么返回。
法II: 可行性剪枝。举个简单的例子,如图,问作者能否在正好第11秒的时候避过各种障碍物最终取得爱心,作者每秒能且只能移动一格,允许走重复的格子。

答案是永远不可能。因为无论怎么走,都只能在第偶数秒到达爱心,这是由他们的曼哈顿距离(两点的XY坐标差的绝对值之和)的奇偶性决定的。
6.1Recursion with backtracking
- 131. Palindrome Partitioning
- 78. Subsets
- 90. Subsets II (no duplicates)
- 77. Combinations
- 46. Permutations
- 47. Permutations II (no duplicates)
- 39. Combination Sum
- 40. Combination Sum II (no duplicates)
- 17.Letter Combinations of a Phone Number
- 22. Generate Parentheses
- 93. Restore IP Addresses
- 44. Wildcard Matching
- 10.Regular Expression Matching
- 51. N-Queens
- 52. N-Queens II
- 37. Sudoku Solver
6.2 Divide and Conquer, 二分法
- 50. Pow(x, n)
- 29. Divide Two Integers
7. Dynamique programming
- 53. Maximum Subarray
- 134. Gas Station
线性模型:状态的排布呈线性
- 42. Trapping Rain Water
- 60. Permutation Sequence
- 121. Best Time to Buy and Sell Stock
- 122. Best Time to Buy and Sell Stock II
- 123. Best Time to Buy and Sell Stock III
- 70. Climbing Stairs
- 91. Decode Ways
- 45. Jump Game II
区间模型:
- 132. Palindrome Partitioning II
- <编程之美> P44, 191-193
- 139. Word Break
- 140. Word Break II
- 97. Interleaving String
- 72. Edit Distance
- 115. Distinct Subsequences
87. Scramble String
8. Greedy
- 55. Jump Game
- 149. Max Points on a Line
9. Numerique analysis
- 65. Valid Number
- 66. Plus One
- 2. Add Two Numbers
- 67. Add Binary
- 13. Roman to Integer
- 12. Integer to Roman
- 8. String to Integer (atoi)
- 7. Reverse Integer
- 9 Palindrome Number
10. segment, project
- 56. Merge Intervals
- 57. Insert Interval
- <编程之美> P50-51
11. 字符串查找
- 14. Longest Common Prefix
- 28. Implement strStr()
- 5. Longest Palindromic Substring (KMP)
12. Bit Operation
- 89. Gray Code
- 136. Single Number
- 137. Single Number II
- p95,p140, p141,p172
- Permutations p173
- Parenthese p174
- pennies p176
- Queen 177
XIV. optimization <珠玑>
- malloc的优化 <珠玑>p92
- string连接的优化p100
- 数据压缩 <珠玑>p100-101
- 哨兵(一元数组、链表、箱、BST)<珠玑>p137
- 随机数 <珠玑>p120(减少生成次数P125/9 未知n p125/10)
Leetcode catalogue的更多相关文章
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
随机推荐
- OpenVPN 部署
https://blog.frognew.com/2017/09/installing-openvpn.html#21-%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96 为了方 ...
- 执行npm install报错:npm ERR! code EINTEGRITY
命令行执行npm install报错如下: D:\frontend\viewsdev>npm install npm ERR! code EINTEGRITY npm ERR! sha512-8 ...
- java 简洁的分层实现
1.分页实现 分页实现是将所有查询结果保存在session对象或集合中,翻页时从session对象或集合中取出一页所需的数据显示.但是这种方法有两个最主要的缺点:一是用户看到的可能是过期数据:二是如果 ...
- 搭建基于hyperledger fabric的联盟社区(八) --Fabric证书解析
一.证书目录解析 通过cryptogen生成所有证书文件后,以peerOrgannizations的第一个组织树org1为例,每个目录和对应文件的功能如下: ca: 存放组织的根证书和对应的私 ...
- CentOS部署NetCore - 1. 安装CentOS 7 & 安装 Nginx
1. 环境: Win7 64bit 2. 准备: VMWare(12.0.0 build-2985596) CentOS 7 Minimal ISO (http://isoredirect.cento ...
- socket 阻塞,同步、I/O模型
1. 概念理解 在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式: 同步: 所谓同步,就是在发出一个功能调用时, ...
- mysql 数据库 自动截取数据的问题---mysql的sql_model的四种模式:宽松模式、严格模式
mysql支持的sql_mode模式:ANSI.TRADITIONAL.STRICT_ALL_TABLES和STRICT_TRANS_TABLES. ANSI模式:宽松模式,对插入数据进行校验,如果不 ...
- Mybatis动态构建Sql(无实体类)
MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑. 例如,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询 ...
- Idea2016远程调试Java项目
一.在IDEA中配置远程tomcat 1.打开配置页面 选择"+" → "Tomcat Server" → "Remote" 填写名称和目标 ...
- OD 实验(十四) - 内嵌补丁
内嵌补丁(inline patch): 内嵌补丁指在程序文件中把补丁代码写入文件里面达到破解的目的 如果修改某行语句会影响后面的语句,例如某语句占用 3 个字节,修改完变为 5 个字节,会覆盖后面的语 ...