LeetCode算法题目解答汇总

LeetCode算法题目解答汇总

只要不是特别忙或者特别不方便,最近一直保持着每天做几道算法题的规律,到后来随着难度的增加,每天做的题目越来越少。我的初衷就是练习,因为一方面我本身算法基础并不好,再一方面是因为工作以后传统意义上所谓算法的东西接触还是太少。为了题目查找方便起见,我把之前几篇陆陆续续贴出来的我对LeetCode上面算法题的解答汇总在下面,CTRL+F就可以比较方便地找到。一共154道题,这个数量大概是两个月前的数量,现在其实题目的数目已经超过这个数了,当然,我没有继续更新。下面表格里面的Acceptance和Difficulty的Easy/Medium/Hard的分类都是来自LeetCode上面的数据,而Difficulty括号里面的数值和Frequency则来自这个文档

总体来说,做LeetCode的题目收获还是很大的。而这种可以很快获得代码正确性和性能即使的反馈的方式,对算法提高也是很有帮助的。有的题目困难,主要包括两方面的原因,有的是思路比较怪异,用常规思路去解题往往时间复杂度或者空间复杂度过高,还有的则是需要考虑的情况比较复杂,case众多,很容易遗漏。

Title Acceptance Difficulty Frequency
Palindrome Number 28.8% Easy (2) 2
ZigZag Conversion 23.4% Easy (3) 1
Valid Sudoku 27.6% Easy (2) 2
Add Binary 25.5% Easy (2) 4
Valid Parentheses 28.2% Easy (2) 5
Valid Palindrome 22.2% Easy (2) 5
Balanced Binary Tree 32.5% Easy (1) 2
Valid Number 11.0% Easy (2) 5
Symmetric Tree 31.6% Easy (1) 2
String to Integer (atoi) 14.2% Easy (2) 5
Same Tree 41.8% Easy (1) 1
Binary Tree Level Order Traversal 30.6% Easy (3) 4
Binary Tree Level Order Traversal II 31.0% Easy (3) 1
Roman to Integer 33.9% Easy (2) 4
Reverse Integer 39.8% Easy (2) 3
Remove Nth Node From End of List 29.3% Easy (2) 3
Remove Element 33.0% Easy (1) 4
Remove Duplicates from Sorted List 34.7% Easy (1) 3
Climbing Stairs 34.0% Easy (2) 5
Remove Duplicates from Sorted Array 32.2% Easy (1) 3
Plus One 31.4% Easy (1) 2
Path Sum 30.4% Easy (1) 3
Pascal’s Triangle II 30.1% Easy (2) 1
Pascal’s Triangle 31.1% Easy (2) 1
Minimum Depth of Binary Tree 29.4% Easy (1) 1
Merge Two Sorted Lists 33.2% Easy (2) 5
Merge Sorted Array 31.8% Easy (2) 5
Maximum Depth of Binary Tree 43.8% Easy (1) 1
Longest Common Prefix 27.0% Easy (2) 1
Count and Say 26.7% Easy (2) 2
Length of Last Word 29.0% Easy (1) 1
Implement strStr() 21.9% Easy (4) 5
Divide Two Integers 16.6% Medium (4) 3
3Sum 16.7% Medium (3) 5
Evaluate Reverse Polish Notation 19.9% Medium  
Find Minimum in Rotated Sorted Array 31.7% Medium  
Word Search 19.8% Medium (3) 4
Word Ladder 18.4% Medium (3) 5
Flatten Binary Tree to Linked List 28.2% Medium (3) 3
Gas Station 25.9% Medium  
Generate Parentheses 31.4% Medium (3) 4
Gray Code 32.1% Medium (4) 2
Word Break 21.3% Medium  
Validate Binary Search Tree 25.9% Medium (3) 5
Insertion Sort List 25.3% Medium  
Integer to Roman 33.8% Medium (3) 4
4Sum 21.4% Medium (3) 2
Jump Game 27.2% Medium (3) 2
Add Two Numbers 22.9% Medium (3) 4
Anagrams 23.9% Medium (3) 4
Decode Ways 16.2% Medium (3) 4
Letter Combinations of a Phone Number 26.4% Medium (3) 3
Linked List Cycle 35.7% Medium  
Linked List Cycle II 30.8% Medium  
Best Time to Buy and Sell Stock 31.2% Medium (2) 1
Unique Paths II 27.9% Medium (3) 3
Longest Palindromic Substring 20.6% Medium (4) 2
Longest Substring Without Repeating Characters 22.2% Medium (3) 2
Unique Paths 31.7% Medium (2) 3
Unique Binary Search Trees II 27.3% Medium (4) 1
Unique Binary Search Trees 36.5% Medium (3) 1
Two Sum 18.4% Medium (2) 5
Convert Sorted List to Binary Search Tree 27.3% Medium (4) 3
Maximum Product Subarray 15.9% Medium  
Maximum Subarray 34.0% Medium (3) 3
Triangle 26.6% Medium (3) 1
Best Time to Buy and Sell Stock II 36.6% Medium (3) 1
Swap Nodes in Pairs 32.4% Medium (2) 4
Convert Sorted Array to Binary Search Tree 32.9% Medium (2) 3
Container With Most Water 31.3% Medium (3) 2
Minimum Path Sum 31.0% Medium (3) 3
Surrounded Regions 14.2% Medium (4) 3
Multiply Strings 20.5% Medium (4) 3
Sum Root to Leaf Numbers 29.7% Medium (2) 4
Subsets II 27.0% Medium (4) 2
Next Permutation 25.4% Medium (5) 2
3Sum Closest 27.0% Medium (3) 1
Palindrome Partitioning 25.9% Medium (3) 4
Subsets 27.9% Medium (3) 4
Partition List 27.0% Medium (3) 3
Construct Binary Tree from Inorder and Postorder Traversal 26.6% Medium  
Construct Binary Tree from Preorder and Inorder Traversal 26.5% Medium  
Combinations 30.0% Medium (3) 4
Combination Sum II 24.7% Medium (4) 2
Path Sum II 26.9% Medium (2) 2
Permutation Sequence 22.3% Medium (5) 1
Permutations 31.2% Medium (3) 4
Sqrt(x) 22.3% Medium (4) 4
Combination Sum 26.8% Medium (3) 3
Populating Next Right Pointers in Each Node 35.3% Medium (3) 3
Spiral Matrix II 30.8% Medium (3) 2
Pow(x, n) 25.9% Medium (3) 5
Spiral Matrix 20.6% Medium (4) 2
Sort List 20.6% Medium  
Clone Graph 23.0% Medium  
Remove Duplicates from Sorted Array II 30.6% Medium (2) 2
Sort Colors 32.1% Medium (4) 2
Remove Duplicates from Sorted List II 24.8% Medium (3) 3
Binary Tree Zigzag Level Order Traversal 26.5% Medium (4) 3
Binary Tree Preorder Traversal 35.5% Medium  
Reorder List 20.4% Medium  
Restore IP Addresses 20.5% Medium (3) 3
Single Number II 33.8% Medium  
Reverse Linked List II 26.1% Medium (3) 2
Single Number 45.6% Medium  
Reverse Words in a String 14.0% Medium  
Simplify Path 19.9% Medium (3) 1
Rotate Image 31.2% Medium (4) 2
Rotate List 22.0% Medium (3) 2
Binary Tree Inorder Traversal 35.5% Medium (4) 3
Set Matrix Zeroes 30.8% Medium (3) 5
Search a 2D Matrix 31.2% Medium (3) 3
Search for a Range 27.4% Medium (4) 3
Search Insert Position 34.9% Medium (2) 2
Search in Rotated Sorted Array II 30.9% Medium (5) 3
Text Justification 14.0% Hard (4) 2
Search in Rotated Sorted Array 28.6% Hard (4) 3
Binary Tree Maximum Path Sum 20.2% Hard (4) 2
Reverse Nodes in k-Group 24.9% Hard (4) 2
Binary Tree Postorder Traversal 31.0% Hard  
Candy 19.3% Hard  
Edit Distance 25.5% Hard (4) 3
Recover Binary Search Tree 23.7% Hard (4) 2
Populating Next Right Pointers in Each Node II 30.7% Hard (4) 2
Permutations II 25.0% Hard (4) 2
Best Time to Buy and Sell Stock III 22.4% Hard (4) 1
Palindrome Partitioning II 18.3% Hard (4) 3
N-Queens II 33.9% Hard (4) 3
Substring with Concatenation of All Words 18.1% Hard (3) 1
Sudoku Solver 20.9% Hard (4) 2
N-Queens 25.9% Hard (4) 3
Minimum Window Substring 18.1% Hard (4) 2
Merge k Sorted Lists 21.2% Hard (3) 4
Merge Intervals 20.9% Hard (4) 5
Scramble String 22.8% Hard (5) 2
Trapping Rain Water 28.9% Hard (4) 2
Median of Two Sorted Arrays 17.6% Hard (5) 3
Maximal Rectangle 21.5% Hard (5) 1
Max Points on a Line 11.2% Hard  
LRU Cache 14.1% Hard  
Longest Valid Parentheses 19.7% Hard (4) 1
Longest Consecutive Sequence 28.2% Hard (4) 3
Copy List with Random Pointer 23.5% Hard  
Largest Rectangle in Histogram 21.5% Hard (5) 2
Jump Game II 24.7% Hard (4) 2
Interleaving String 19.5% Hard (5) 2
Insert Interval 20.7% Hard (4) 5
Wildcard Matching 14.3% Hard (5) 3
Distinct Subsequences 25.0% Hard (4) 2
Word Break II 16.6% Hard  
First Missing Positive 22.6% Hard (5) 2
Word Ladder II 11.5% Hard (1) 1
Find Minimum in Rotated Sorted Array II 27.9% Hard  
Regular Expression Matching 20.2% Hard (5) 3

文章未经特殊标明皆为本人原创,未经许可不得用于任何商业用途,转载请保持完整性并注明来源链接《四火的唠叨》

分享到:

发表评论

关闭菜单