LeetCode 算法题目解答
为了督促自己能够每天刷一道算法题,特将LeetCode常见题目列出,之后每天一题,每完成一题都会总结解答并链接到该博客相应的题目上。
Title | Difficulty | |
---|---|---|
Palindrome Number | Easy (2) | |
ZigZag Conversion | Easy (3) | |
Valid Sudoku | Easy (2) | |
Add Binary | Easy (2) | |
Valid Parentheses | Easy (2) | |
Valid Palindrome | Easy (2) | |
Balanced Binary Tree | Easy (1) | |
Valid Number | Easy (2) | |
Symmetric Tree | Easy (1) | |
String to Integer (atoi) | Easy (2) | |
Same Tree | Easy (1) | |
Binary Tree Level Order Traversal | Easy (3) | |
Binary Tree Level Order Traversal II | Easy (3) | |
Roman to Integer | Easy (2) | |
Reverse Integer | Easy (2) | |
Remove Nth Node From End of List | Easy (2) | |
Remove Element | Easy (1) | |
Remove Duplicates from Sorted List | Easy (1) | |
Climbing Stairs | Easy (2) | |
Remove Duplicates from Sorted Array | Easy (1) | |
Plus One | Easy (1) | |
Path Sum | Easy (1) | |
Pascal’s Triangle II | Easy (2) | |
Pascal’s Triangle | Easy (2) | |
Minimum Depth of Binary Tree | Easy (1) | |
Merge Two Sorted Lists | Easy (2) | |
Merge Sorted Array | Easy (2) | |
Maximum Depth of Binary Tree | Easy (1) | |
Longest Common Prefix | Easy (2) | |
Count and Say | Easy (2) | |
Length of Last Word | Easy (1) | |
Implement strStr() | Easy (4) | |
Divide Two Integers | Medium (4) | |
3Sum | Medium (3) | |
Evaluate Reverse Polish Notation | Medium | |
Find Minimum in Rotated Sorted Array | Medium | |
Word Search | Medium (3) | |
Word Ladder | Medium (3) | |
Flatten Binary Tree to Linked List | Medium (3) | |
Gas Station | Medium | |
Generate Parentheses | Medium (3) | |
Gray Code | Medium (4) | |
Word Break | Medium | |
Validate Binary Search Tree | Medium (3) | |
Insertion Sort List | Medium | |
Integer to Roman | Medium (3) | |
4Sum | Medium (3) | |
Jump Game | Medium (3) | |
Add Two Numbers | Medium (3) | |
Anagrams | Medium (3) | |
Decode Ways | Medium (3) | |
Letter Combinations of a Phone Number | Medium (3) | |
Linked List Cycle | Medium | |
Linked List Cycle II | Medium | |
Best Time to Buy and Sell Stock | Medium (2) | |
Unique Paths II | Medium (3) | |
Longest Palindromic Substring | Medium (4) | |
Longest Substring Without Repeating Characters | Medium (3) | |
Unique Paths | Medium (2) | |
Unique Binary Search Trees II | Medium (4) | |
Unique Binary Search Trees | Medium (3) | |
Two Sum | Medium (2) | |
Convert Sorted List to Binary Search Tree | Medium (4) | |
Maximum Product Subarray | Medium | |
Maximum Subarray | Medium (3) | |
Triangle | Medium (3) | |
Best Time to Buy and Sell Stock II | Medium (3) | |
Swap Nodes in Pairs | Medium (2) | |
Convert Sorted Array to Binary Search Tree | Medium (2) | |
Container With Most Water | Medium (3) | |
Minimum Path Sum | Medium (3) | |
Surrounded Regions | Medium (4) | |
Multiply Strings | Medium (4) | |
Sum Root to Leaf Numbers | Medium (2) | |
Subsets II | Medium (4) | |
Next Permutation | Medium (5) | |
3Sum Closest | Medium (3) | |
Palindrome Partitioning | Medium (3) | |
Subsets | Medium (3) | |
Partition List | Medium (3) | |
Construct Binary Tree from Inorder and Postorder Traversal | Medium | |
Construct Binary Tree from Preorder and Inorder Traversal | Medium | |
Combinations | Medium (3) | |
Combination Sum II | Medium (4) | |
Path Sum II | Medium (2) | |
Permutation Sequence | Medium (5) | |
Permutations | Medium (3) | |
Sqrt(x) | Medium (4) | |
Combination Sum | Medium (3) | |
Populating Next Right Pointers in Each Node | Medium (3) | |
Spiral Matrix II | Medium (3) | |
Pow(x, n) | Medium (3) | |
Spiral Matrix | Medium (4) | |
Sort List | Medium | |
Clone Graph | Medium | |
Remove Duplicates from Sorted Array II | Medium (2) | |
Sort Colors | Medium (4) | |
Remove Duplicates from Sorted List II | Medium (3) | |
Binary Tree Zigzag Level Order Traversal | Medium (4) | |
Binary Tree Preorder Traversal | Medium | |
Reorder List | Medium | |
Restore IP Addresses | Medium (3) | |
Single Number II | Medium | |
Reverse Linked List II | Medium (3) | |
Single Number | Medium | |
Reverse Words in a String | Medium | |
Simplify Path | Medium (3) | |
Rotate Image | Medium (4) | |
Rotate List | Medium (3) | |
Binary Tree Inorder Traversal | Medium (4) | |
Set Matrix Zeroes | Medium (3) | |
Search a 2D Matrix | Medium (3) | |
Search for a Range | Medium (4) | |
Search Insert Position | Medium (2) | |
Search in Rotated Sorted Array II | Medium (5) | |
Text Justification | Hard (4) | |
Search in Rotated Sorted Array | Hard (4) | |
Binary Tree Maximum Path Sum | Hard (4) | |
Reverse Nodes in k-Group | Hard (4) | |
Binary Tree Postorder Traversal | Hard | |
Candy | Hard | |
Edit Distance | Hard (4) | |
Recover Binary Search Tree | Hard (4) | |
Populating Next Right Pointers in Each Node II | Hard (4) | |
Permutations II | Hard (4) | |
Best Time to Buy and Sell Stock III | Hard (4) | |
Palindrome Partitioning II | Hard (4) | |
N-Queens II | Hard (4) | |
Substring with Concatenation of All Words | Hard (3) | |
Sudoku Solver | Hard (4) | |
N-Queens | Hard (4) | |
Minimum Window Substring | Hard (4) | |
Merge k Sorted Lists | Hard (3) | |
Merge Intervals | Hard (4) | |
Scramble String | Hard (5) | |
Trapping Rain Water | Hard (4) | |
Median of Two Sorted Arrays | Hard (5) | |
Maximal Rectangle | Hard (5) | |
Max Points on a Line | Hard | |
LRU Cache | Hard | |
Longest Valid Parentheses | Hard (4) | |
Longest Consecutive Sequence | Hard (4) | |
Copy List with Random Pointer | Hard | |
Largest Rectangle in Histogram | Hard (5) | |
Jump Game II | Hard (4) | |
Interleaving String | Hard (5) | |
Insert Interval | Hard (4) | |
Wildcard Matching | Hard (5) | |
Distinct Subsequences | Hard (4) | |
Word Break II | Hard | |
First Missing Positive | Hard (5) | |
Word Ladder II | Hard (1) | |
Find Minimum in Rotated Sorted Array II | Hard | |
Regular Expression Matching | Hard (5) | |
Invert Binary Tree | Easy | |
Implement Stack using Queues | Medium | |
Basic Calculator | Medium | |
Rectangle Area | Easy | |
Count Complete Tree Nodes | Medium | |
Maximal Square | Medium | |
Contains Duplicate III | Medium | |
Contains Duplicate II | Easy | |
The Skyline Problem | Hard | |
Contains Duplicate | Easy | |
Combination Sum III | Medium | |
Kth Largest Element in an Array | Medium | |
Shortest Palindrome | Hard | |
House Robber II | Medium | |
Word Search II | Hard | |
Add and Search Word – Data structure design | Medium | |
Course Schedule II | Medium | |
Minimum Size Subarray Sum | Medium | |
Implement Trie (Prefix Tree) | Medium | |
Course Schedule | Medium | |
Reverse Linked List | Easy | |
Isomorphic Strings | Easy | |
Count Primes | Easy | |
Remove Linked List Elements | Easy | |
Happy Number | Easy | |
Bitwise AND of Numbers Range | Medium | |
Number of Islands | Medium | |
Binary Tree Right Side View | Medium | |
House Robber | Easy | |
Number of 1 Bits | Easy | |
Reverse Bits | Easy | |
Rotate Array | Easy | |
Best Time to Buy and Sell Stock IV | Hard | |
Repeated DNA Sequences | Medium | |
Reverse Words in a String II | Medium | |
Largest Number | Medium | |
Dungeon Game | Hard | |
Binary Search Tree Iterator | Medium | |
Factorial Trailing Zeroes | Easy | |
Excel Sheet Column Number | Easy | |
Two Sum III – Data structure design | Easy | |
Majority Element | Easy | |
Excel Sheet Column Title | Easy | |
Two Sum II – Input array is sorted | Medium | |
Fraction to Recurring Decimal | Medium | |
Compare Version Numbers | Easy | |
Maximum Gap | Hard | |
Missing Ranges | Medium | |
Find Peak Element | Medium | |
One Edit Distance | Medium | |
Intersection of Two Linked Lists | Easy | |
Longest Substring with At Most Two Distinct Characters | Hard | |
Read N Characters Given Read4 II – Call multiple times | Hard | |
Read N Characters Given Read4 | Easy | |
Binary Tree Upside Down | Medium | |
Min Stack | Easy | |
Minimum Height Trees | Medium | |
Best Time to Buy and Sell Stock with Cooldown | Medium | |
Range Sum Query – Mutable | Medium | |
Additive Number | Medium | |
Range Sum Query 2D – Immutable | Medium | |
Range Sum Query – Immutable | Easy | |
Remove Invalid Parentheses | Hard | |
Longest Increasing Subsequence | Medium | |
Bulls and Cows | Easy | |
Serialize and Deserialize Binary Tree | Medium | |
Find Median from Data Stream | Hard | |
Nim Game | Easy | |
Word Pattern | Easy | |
Game of Life | Medium | |
Find the Duplicate Number | Hard | |
Peeking Iterator | Medium | |
Move Zeroes | Easy | |
Expression Add Operators | Hard | |
Perfect Squares | Medium | |
First Bad Version | Easy | |
H-Index II | Medium | |
H-Index | Medium | |
Integer to English Words | Medium | |
Missing Number | Medium | |
Ugly Number II | Medium | |
Ugly Number | Easy | |
Single Number III | Medium | |
Add Digits | Easy | |
Binary Tree Paths | Easy | |
Valid Anagram | Easy | |
Different Ways to Add Parentheses | Medium | |
Search a 2D Matrix II | Medium | |
Sliding Window Maximum | Hard | |
Product of Array Except Self | Medium | |
Delete Node in a Linked List | Easy | |
Lowest Common Ancestor of a Binary Tree | Medium | |
Lowest Common Ancestor of a Binary Search Tree | Easy | |
Palindrome Linked List | Easy | |
Number of Digit One | Medium | |
Implement Queue using Stacks | Easy | |
Power of Two | Easy | |
Kth Smallest Element in a BST | Medium | |
Majority Element II | Medium | |
Summary Ranges | Easy | |
Basic Calculator II | Medium | |
Sum of Two Integers | Easy | |
Largest Divisible Subset | Medium | |
Valid Perfect Square | Medium | |
Water and Jug Problem | Medium | |
Max Sum of Rectangle No Larger Than K | Hard | |
Count Numbers with Unique Digits | Medium | |
Design Twitter | Medium | |
Russian Doll Envelopes | Hard | |
Data Stream as Disjoint Intervals | Hard | |
Intersection of Two Arrays II | Easy | |
Intersection of Two Arrays | Easy | |
Top K Frequent Elements | Medium | |
Reverse Vowels of a String | Easy | |
Reverse String | Easy | |
Integer Break | Medium | |
Power of Four | Easy | |
Flatten Nested List Iterator | Medium | |
Counting Bits | Medium | |
House Robber III | Medium | |
Palindrome Pairs | Hard | |
Self Crossing | Hard | |
Increasing Triplet Subsequence | Medium | |
Reconstruct Itinerary | Medium | |
Verify Preorder Serialization of a Binary Three | Medium | |
Patching Arrays | Hard | |
Longest Increasing Path in a Matrix | Hard | |
Odd Even Linked List | Medium | |
Count of Range Sum | Hard | |
Power of Three | Easy | |
Wiggle Sort II | Medium | |
Coin Change | Medium | |
Create Maximum Number | Hard | |
Bulb Switcher | Medium | |
Maximum Product of Word Lengths | Medium | |
Remove Duplicate Letters | Hard | |
Count of Smaller Numbers After Self | Hard | |
Super Ugly Number | Medium | |
Burst Balloons | Hard |
其他题目总结
Title |
---|
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 |
One Edit Distance |
Missing Ranges |
Two Sum III – Data structure design |
Reverse Words in a String II |
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 |
3Sum Smaller |
Graph Valid Tree |
Paint House II |
Palindrome Permutation |
Palindrome Permutation II |
Alien Dictionary |
Closest Binary Search Tree Value |
Encode and Decode Strings |
Closest Binary Search Tree Value II |
Paint Fence |
Find the Celebrity |
Wiggle Sort |
Zigzag Iterator |
Inorder Successor in BST |
Walls and Gates |
Unique Word Abbreviation |
Word Pattern II |
Flip Game |
Flip Game II |
Best Meeting Point |
Binary Tree Longest Consecutive Sequence |