Leetcode题目分类:类型+难易

=== 十月十五日更 ===

题已刷完,这篇总结还落下不少进度。这个网站本属于个人博客,以后我不想把刷题这种纯找工作的文章发在这里。另外,我回头审视了以前写的一些题解,发现还有不少提升空间,包括对解法的描述和代码的优化。因此我重新做了一个题解网站,也希望能以更加清晰的分类目录和解法帮助读者提升刷题的效率,早点从刷题中走出来,做些更有意思的事。鉴于我需要重新描述大多数题目的解法,新的网站目前只有十来道题,我准备在完成全部题解后再尝试推广,大约在十一月下旬完成。完成后会把这里的题解全部删除。

本篇至此停更。

===

Degree of difficulty from 1~5, 1 is the simplest, 5 is the most difficult.


分类有点散漫,有些是交叉的,目前有 General, String, Linked List (LL), Array, Tree, Recursion, Dynamic Programming (DP), Bit Manipulation (Bit). 分类标签在标题后的括号里,也有些只出现一两次的标签。
我会把值得复习的题发出来,链接在相应标题上,没链接的题一般比较简单,或者是我认为不太有用的题。

有一点需要注意,我刚开始做题时觉得多数题偏难,随着熟练度提升,有些题对我变简单了,但我还是会按照最开始的难度标准来分类。
这里有一篇文章可供参考编程面试的10大算法概念

1
1.1 Remove Duplicates from Sorted List (LL)
1.2 Remove Element (Array)
1.3 Reverse Integer (General)
1.4 Evaluate Reverse Polish Notation (General)
1.5 Binary Tree Level Order Traversal (Tree)- BFS, use one queue (use its current size)
1.6 Populating Next Right Pointers in Each Node (Tree)- BFS
1.7 Populating Next Right Pointers in Each Node II (Tree) – BFS, use two queues, also solve the 1st version
1.8 Validate Binary Search Tree (Tree) – Think about BST features, it’s easy, use in-order traversal
1.9 Binary Tree Level Order Traversal II (Tree) – Same as the first version.
1.10 Add Binary (Bit)
1.11 Length of Last Word (String) – Way easier than I thought.
1.12 Longest Common Prefix (String) – Avoid being verbose.

2
2.1 Binary Tree Preorder Traversal (Tree)
2.2 Integer to Roman – 这题应该不太会考,没啥意思,我们这种老外哪懂罗马数字的书写规则啊 – -
2.3 Roman to Integer – 同上
2.4 Same Tree (Tree, Recursion)
2.5 Search a 2D Matrix (Array) – Binary Search a Matrix, transform 2D coordinates into 1D
2.6 Plus One (Array) – Need to consider some boundary conditions
2.7 Remove duplicates from sorted array (Array) – Try to be not verbose!
2.8 Climbing Stairs (DP)
2.9 Sort Colors (Array)
2.10 Single Number (Bit)
2.11 Pow(x, n) (Recursion) – Naive recursion wouldn’t work, need some modification. DP and recursion both have pros and cons.
2.12 ZigZag Conversion (Array) – Pure math problem…
2.13 Binary Tree Zigzag Level Order Traversal (Tree) – BFS, use Deque as Stack, notice the order to add children nodes
2.14 Unique Binary Search Trees (Recursion, DP) – Recursion or DP (better)
2.15 Binary Tree Inorder Traversal (Tree) – Iterative, Stack(recommend using Deque in Java) 
2.16 Single Number II (Bit) – Bit operation and binary representation of integer
2.17 Merge Sorted Array (Array) – Change perspective of sorted array, compare and fill element from rear, where there is enough space
2.18 Unique Paths (DP)
2.19 Reorder List (LL) – Slow and fast pointers, reverse list, merge list
2.20 Flatten Binary Tree to Linked List (LL)
2.21 Rotate List (LL)
2.22 Search in Rotated Sorted Array – Directly do two binary search
2.23 Search in Rotated Sorted Array II
2.24 Search Insert Position (Array) – Notice the boundary
2.25 Pascal’s Triangle (General) – Fundamental math
2.26 Binary Tree Maximum Path Sum (Tree, Recursion)
2.27 3Sum Closest (General) – Same as 3Sum
2.28 Minimum Path Sum (DP) – Rolling array solution is a bit hard.
2.29 Partition List (LL) – Use two dummy head, make it clear.
2.30 Container With Most Water (General) – 选了两根线以后就把其他线都忽略就好了。
2.31 Rotate Image – 多种解法,关键是找到元素之间的关系,需要一些记忆。
2.32 Merge Intervals (Array) – 这题虽用的是List,但是和Array没区别
2.33 Remove duplicates from sorted array (Array)- 解法很巧妙,核心代码不应超过五行。
2.34 Sqrt(x) – Pure math.
2.35 Anagrams – 注意 anagrams 的中文意思不是回文数。
2.36 Two Sum – 和 Anagrams 的解法一样。
2.37 Multiply Strings – 先做反转字符串,使得相乘过程更清晰,以空间换取可读性,但复杂度不变。

3
3.1 Add Two Numbers (LL)
3.2 Valid Palindrome (General) – 记一些工具函数
3.3 Best Time to Buy and Sell Stock (DP)
3.4 Best Time to Buy and Sell Stock II (DP)
3.5 Best Time to Buy and Sell Stock III (DP) – 常常复习一下
3.6 Swap Nodes in Pairs (LL) – Traverse a list without considering the head node particularly
3.7 Sum Root to Leaf Numbers (Tree)
3.8 Linked List Cycle (LL)
3.9 Same Tree (Tree, Recursion)
3.10 Path Sum (Tree, Recursion or Iteration (hard) )
3.11 Path Sum II (Tree, Recursion)
3.12 Merge Two Sorted Lists (LL)
3.13 Merge k Sorted Lists (LL) – Straightforward way; merge sort way; priority queue way.
3.14 Insertion Sort List (LL) – Easy to get stuck in the first time
3.15 Subsets (Recursion or Iteration)
3.16 Combinations (Recursion and traceback and DFS)
3.17 Triangle (DP) – Bottom-up approach, typical 1D shrink pattern
3.18 Pascal’s Triangle II (General) – Fundamental math. Bottom-up approach, typical 1D shrink pattern
3.19 Copy List with Random Pointer (LL) – Use shadow list
3.20 Spiral Matrix (General) – Note the edge cases, use four boundaries.
3.21 Subsets II (Recursion) – Almost the same as Subsets. Skip the duplicate elements after remove the last element.
3.22 Longest Valid Parentheses (General) – Use a stack to store ‘(‘ index. 
3.23 Remove Duplicates from Sorted List II (LL) – Use a dummy node and a while loop to skip duplicates.
3.24 Unique Paths II (DP)
3.25 Longest Substring Without Repeating Characters (String)
3.26 Set Matrix Zeroes – 答案不太容易想到,但很容易理解,以后 in-place 的题可以考虑存在当前已有的数据结构中,这是个技巧。
3.27 N-Queens (Recursion) – Recursion + Traceback, just like Subsets II problem
3.28 N-Queens II (Recursion) – Same as above.
3.29 Sudoku Solver (Recursion) – Almost the same as above.
3.30 Combination Sum (Recursion) – Same as above.
3.31 Combination Sum II (Recursion) – Same as above.
3.32 Permutations (Recursion) – Same as above.
3.33 Permutations II (Recursion) – Almost the same as I, just add a visited array to avoid repeated access, remember to reset it to 0 when trace back.
3.34 Word Search (Recursion) – Same as above.
3.35 Valid Sudoku (Recursion) – Same as 3.29 Sudoku Solver
3.36 Trapping Rain Water (General)
3.37 Jump Game (General) – 做出来之前不知道这么简单,所以还算难一点,这题不用 DP。
3.38 Jump Game II (General) – 解法容易理解,但不容易想到,多复习。
3.39 First Missing Positive (General) – Constant space implies modifying the original array. 每个正值元素 x 存在 index = x-1 处。
3.40 Largest Rectangle in Histogram (General)
3.41 Decode Ways (DP)
3.42 Simplify Path (General)
3.43 Minimum Window Substring (General)
3.44 Restore IP Addresses (DP + recursion)
3.45 Construct Binary Tree from Preorder and Inorder Traversal (Tree)
3.46 Construct Binary Tree from Inorder and Postorder Traversal (Tree)
3.47 Median of Two Sorted Arrays (Array)
3.48 Gas Station (General)
3.49 Surrounded Regions (BFS)
3.50 Insert Interval


The following questions are hard to solve in one shot.

4
4.1 Letter Combinations of a Phone Number (Recursion) – Iterative version would be harder, haven’t done that yet.
4.2 Reverse Linked List II (LL) – Tricky, need more practice on exchanging nodes.
4.3 Convert Sorted List to Binary Search Tree (DP, Tree)
4.4 Interleaving String (Classic DP situation, Recursion has too many duplicate search branches)
4.5 Wildcard Matching (Greedy)
4.6 Maximal Rectangle
4.7 Edit Distance (DP)

5
5.1 Linked List Cycle II (LL) – Kind of brain teaser
5.2 Binary Tree Postorder Traversal (Tree) – Use iteration instead of recursion
5.3 Word Ladder (Tree) – BFS!
5.4 Palindrome Partitioning (Recursion + DP) – DFS + Recursion + DP
5.5 Sort List (Recursion + DP) – Recursion version is relatively trivial, while DP version is pretty hard
5.6 3Sum, 4Sum and k-sum (General) – Hashmap ways to solve 3Sum and 4Sum, also recursive solution to k-sum, pretty concise
5.7 LRU Cache (General)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值