欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

leetcode问题分析:总述

程序员文章站 2022-04-02 16:33:01
...

前言:

  最近在学着做leetcode上面所有的习题。这里列举出了很多公司面试的问题,撇开功利的目的,对这些问题的研究对于学习总结也有很重要的意义。于是想尝试一下把自己解决问题的思路以及详细的解答都记录下来。在以前的学习中,经常碰到一些比较困难的问题去搜索答案的时候,看到的只是贴的一大堆代码。也许结果是对的,可是没有描述为什么会有这样的结果,这个结果是怎么来的。于是如果问题有一些变化,还是不知道该怎么做。所以问题的核心还是在于它的本质以及背后的思想。

  本文是所有问题以及其解答的一个索引。引用一下本人微博上的一句话:只贴代码不讲思路的其行为比看帖不回帖更可恶 :)

 

问题列表

问题 解答分析
Two Sum  分析解答
Median of Two Sorted Arrays  分析解答
Longest Substring Without Repeating Characters  分析解答
Add Two Numbers  分析解答
Longest Palindromic Substring  分析解答
ZigZag Conversion  分析解答
Reverse Integer  分析解答
String to Integer (atoi)  分析解答
Palindrome Number  分析解答
Regular Expression Matching  分析解答
Container With Most Water  分析解答
Integer to Roman  分析解答
Roman to Integer  分析解答
Longest Common Prefix  分析解答
3Sum  分析解答
3Sum Closest  分析解答
4Sum  分析解答
Letter Combinations of a Phone Number  分析解答
Remove Nth Node From End of List  分析解答
Valid Parentheses  分析解答
Generate Parentheses  分析解答
Merge k Sorted Lists  分析解答
Swap Nodes in Pairs  分析解答
Reverse Nodes in k-Group  分析解答
Remove Duplicates from Sorted Array  分析解答
Remove Element  分析解答
Implement strStr()  分析解答
Divide Two Integers  分析解答
Substring with Concatenation of All Words  分析解答
Next Permutation  分析解答
Longest Valid Parentheses  分析解答
Search in Rotated Sorted Array  分析解答
Search for a Range  分析解答
Search Insert Position  分析解答
Valid Sudoku  分析解答
Sudoku Solver  分析解答
Count and Say  分析解答
Combination Sum  分析解答
Combination Sum II  分析解答
First Missing Positive  分析解答
Trapping Rain Water  分析解答
Multiply Strings  分析解答
Wildcard Matching  分析解答
Jump Game II  分析解答
Permutations  分析解答
Permutations II  分析解答
Rotate Image  分析解答
Group Anagrams  分析解答
Pow(x, n)  分析解答
N-Queens  分析解答
N-Queens II  分析解答
Maximum Subarray  分析解答
Spiral Matrix  分析解答
Jump Game  分析解答
Merge Intervals  分析解答
Insert Interval  分析解答
Length of Last Word  分析解答
Spiral Matrix II  分析解答
Permutation Sequence  分析解答
Rotate List  分析解答
Unique Paths  分析解答
Unique Paths II  分析解答
Minimum Path Sum  分析解答
Merge Two Sorted Lists  分析解答
Add Binary  分析解答
Valid Number  分析解答
Plus One  分析解答
Text Justification  分析解答
Sqrt(x)  分析解答
Climbing Stairs  分析解答
Simplify Path  分析解答
Edit Distance  分析解答
Set Matrix Zeroes  分析解答
Search a 2D Matrix  分析解答
Sort Colors  分析解答
Minimum Window Substring  分析解答
Combinations  分析解答
Subsets  分析解答
Word Search  分析解答
Remove Duplicates from Sorted Array II  分析解答
Search in Rotated Sorted Array II  分析解答
Remove Duplicates from Sorted List  分析解答
Remove Duplicates from Sorted List II  分析解答
Largest Rectangle in Histogram  分析解答
Maximal Rectangle  分析解答
Partition List  分析解答
Scramble String 分析解答 
Merge Sorted Array  分析解答
Gray Code  分析解答
Decode Ways  分析解答
Subsets II  分析解答
Reverse Linked List II  分析解答
Restore IP Addresses  分析解答
Binary Tree Inorder Traversal  分析解答
Unique Binary Search Trees  分析解答
Unique Binary Search Trees II  分析解答
Interleaving String  分析解答
Validate Binary Search Tree  分析解答
Recover Binary Search Tree  分析解答
Same Tree  分析解答
Symmetric Tree  分析解答
Binary Tree Level Order Traversal  分析解答
Binary Tree Zigzag Level Order Traversal  分析解答
Maximum Depth of Binary Tree  分析解答
Construct Binary Tree from Preorder and Inorder Traversal  分析解答
Construct Binary Tree from Inorder and Postorder Traversal  分析解答
Binary Tree Level Order Traversal II  分析解答
Convert Sorted Array to Binary Search Tree  分析解答
Convert Sorted List to Binary Search Tree  分析解答
Balanced Binary Tree  分析解答
Minimum Depth of Binary Tree  分析解答
Path Sum  分析解答
Path Sum II  分析解答
Flatten Binary Tree to Linked List  分析解答
Distinct Subsequences  分析解答
Populating Next Right Pointers in Each Node  分析解答
Populating Next Right Pointers in Each Node II  分析解答
Pascal's Triangle  分析解答
Pascal's Triangle II  分析解答
Triangle  分析解答
Best Time to Buy and Sell Stock  分析解答
Best Time to Buy and Sell Stock II  分析解答
Best Time to Buy and Sell Stock III  分析解答
Binary Tree Maximum Path Sum  分析解答
Valid Palindrome  分析解答
Word Ladder  分析解答
Word Ladder II  
Longest Consecutive Sequence  分析解答
Sum Root to Leaf Numbers  分析解答
Surrounded Regions  分析解答
Palindrome Partitioning  分析解答
Palindrome Partitioning II  分析解答
Clone Graph  分析解答
Gas Station  分析解答
Candy  分析解答
Single Number  分析解答
Single Number II  分析解答
Copy List with Random Pointer  分析解答
Word Break  分析解答
Word Break II  分析解答
Linked List Cycle  分析解答
Linked List Cycle II  分析解答
Reorder List  分析解答
Binary Tree Preorder Traversal  分析解答
Binary Tree Postorder Traversal  分析解答
LRU Cache  分析解答
Insertion Sort List  分析解答
Sort List  分析解答
Max Points on a Line  分析解答
Evaluate Reverse Polish Notation  分析解答
Reverse Words in a String  分析解答
Maximum Product Subarray  分析解答
Find Minimum in Rotated Sorted Array  分析解答
Find Minimum in Rotated Sorted Array II  分析解答
Min Stack  分析解答
Binary Tree Upside Down  分析解答
Read N Characters Given Read4   
Read N Characters Given Read4 II - Call multiple times  
Longest Substring with At Most Two Distinct Characters  
Intersection of Two Linked Lists  
One Edit Distance  
Find Peak Element  
Missing Ranges  
Maximum Gap  
Compare Version Numbers  
Fraction to Recurring Decimal  
Two Sum II - Input array is sorted  
Excel Sheet Column Title  
Majority Element  
Two Sum III - Data structure design  
Excel Sheet Column Number  
Factorial Trailing Zeroes  
Binary Search Tree Iterator  
Dungeon Game  
Largest Number  
Reverse Words in a String II  
Repeated DNA Sequences  
Best Time to Buy and Sell Stock IV  
Rotate Array  
Reverse Bits  
Number of 1 Bits  
House Robber  
Binary Tree Right Side View  
Number of Islands  
Bitwise AND of Numbers Range  
Happy Number  
Remove Linked List Elements  
Count Primes  
Isomorphic Strings  
Reverse Linked List  
Course Schedule  
Implement Trie (Prefix Tree)  
Minimum Size Subarray Sum  
Course Schedule II  
Add and Search Word - Data structure design  
Word Search II  
House Robber II  
Shortest Palindrome  
Kth Largest Element in an Array  
Combination Sum III  
Contains Duplicate  
The Skyline Problem  
Contains Duplicate II  
Contains Duplicate III  
Maximal Square  
Count Complete Tree Nodes  
Rectangle Area  
Basic Calculator  
Implement Stack using Queues  
Invert Binary Tree  
Basic Calculator II  
Summary Ranges  
Majority Element II  
Kth Smallest Element in a BST  
Power of Two  
Implement Queue using Stacks  
Number of Digit One  分析解答
Palindrome Linked List  
Lowest Common Ancestor of a Binary Search Tree  分析解答
Lowest Common Ancestor of a Binary Tree  分析解答
Delete Node in a Linked List  
Product of Array Except Self  
Sliding Window Maximum  
Search a 2D Matrix II  
Different Ways to Add Parentheses  
Valid Anagram  
Shortest Word Distance  
Shortest Word Distance II  
Shortest Word Distance III  
Strobogrammatic Number  
Strobogrammatic Number II  
Strobogrammatic Number III  
Group Shifted Strings  
Count Univalue Subtrees  
Flatten 2D Vector  
Meeting Rooms  
Meeting Rooms II  
Factor Combinations  
Verify Preorder Sequence in Binary Search Tree  
Paint House  
Binary Tree Paths  
Add Digits  
3Sum Smaller  
Single Number III  
Graph Valid Tree  
Ugly Number  
Ugly Number II  
Paint House II  
Palindrome Permutation  
Palindrome Permutation II  
Missing Number  
Alien Dictionary  
Closest Binary Search Tree Value  
Encode and Decode Strings  
Closest Binary Search Tree Value II  
Integer to English Words  
H-Index  
H-Index II  
Paint Fence  
Find the Celebrity  
First Bad Version  
Perfect Squares  
Wiggle Sort  
Zigzag Iterator  
Expression Add Operators  
Move Zeroes  
Peeking Iterator  
Inorder Successor in BST  
Walls and Gates  
Find the Duplicate Number  
Unique Word Abbreviation  
Game of Life  
Word Pattern  
Word Pattern II  
Nim Game  
Flip Game  
Flip Game II  
Find Median from Data Stream  
Best Meeting Point  
Serialize and Deserialize Binary Tree  
Binary Tree Longest Consecutive Sequence  
Bulls and Cows  
Longest Increasing Subsequence  
Remove Invalid Parentheses  
Smallest Rectangle Enclosing Black Pixels  
Range Sum Query - Immutable  
Range Sum Query 2D - Immutable  
Number of Islands II  
Additive Number  
Range Sum Query - Mutable  
Range Sum Query 2D - Mutable  
Best Time to Buy and Sell Stock with Cooldown  
Minimum Height Trees  
Sparse Matrix Multiplication  
Burst Balloons  
Super Ugly Number  
Binary Tree Vertical Order Traversal  
Count of Smaller Numbers After Self  
Remove Duplicate Letters  
Shortest Distance from All Buildings  
Maximum Product of Word Lengths  
Bulb Switcher  
Generalized Abbreviation  
Create Maximum Number  
Coin Change  
Number of Connected Components in an Undirected Graph  
Wiggle Sort II  
Maximum Size Subarray Sum Equals k  
Power of Three  
Count of Range Sum  
Odd Even Linked List  
Longest Increasing Path in a Matrix  
Patching Array  
Verify Preorder Serialization of a Binary Tree  
Reconstruct Itinerary  
Largest BST Subtree  
Increasing Triplet Subsequence  
Self Crossing  
Palindrome Pairs  
House Robber III  
Counting Bits  
Nested List Weight Sum  
Longest Substring with At Most K Distinct Characters  
Flatten Nested List Iterator  
Power of Four  
Integer Break  
Reverse String  
Reverse Vowels of a String  
Moving Average from Data Stream  
Top K Frequent Elements  
Design Tic-Tac-Toe   
Intersection of Two Arrays  
Intersection of Two Arrays II  
Android Unlock Patterns  
Data Stream as Disjoint Intervals  
Design Snake Game  
Russian Doll Envelopes  
Line Reflection  
Count Numbers with Unique Digits  
Rearrange String k Distance Apart   
Logger Rate Limiter  
Sort Transformed Array  
Bomb Enemy  
Design Hit Counter  
Max Sum of Rectangle No Larger Than K  
Nested List Weight Sum II  
Water and Jug Problem  
Find Leaves of Binary Tree  
Valid Perfect Square  
Largest Divisible Subset  
Plus One Linked List  
Range Addition  
Sum of Two Integers  
Super Pow  
Find K Pairs with Smallest Sums  
Guess Number Higher or Lower  
Guess Number Higher or Lower II  
Wiggle Subsequence  
Combination Sum IV  
Kth Smallest Element in a Sorted Matrix  
Design Phone Directory  
Insert Delete GetRandom O(1)  
Insert Delete GetRandom O(1) - Duplicates allowed  
Linked List Random Node  
Ransom Note  
Shuffle an Array  
Mini Parser
 
Lexicographical Numbers  
First Unique Character in a String  
Longest Absolute File Path  
Find the Difference  
Perfect Rectangle  
Is Subsequence  
UTF-8 Validation  
Decode String  
Longest Substring with At Least K Repeating Characters  
Rotate Function
 
Integer Replacement
 
Random Pick Index  
Evaluate Division  
Nth Digit   
Binary Watch   
Remove K Digits  
Frog Jump  
Sum of Left Leaves  
Convert a Number to Hexadecimal   
Queue Reconstruction by Height  
Trapping Rain Water II   
Valid Word Abbreviation  
Longest Palindrome   
Split Array Largest Sum