Top 100 Liked Problems Solutions

  • 1 - 10

# Title Solution Acceptance Difficulty Frequency
1 Two Sum 40.2% Easy
2 Add Two Numbers 30.4% Medium
3 Longest Substring Without Repeating Characters 26.1% Medium
4 Median of Two Sorted Arrays 25.3% Hard
5 Longest Palindromic Substring 26.4% Medium
10 Regular Expression Matching 24.9% Hard
11 Container With Most Water 42.1% Medium
15 3Sum 23.2% Medium
17 Letter Combinations of a Phone Number 40.1% Medium
19 Remove Nth Node From End of List 33.9% Medium

1. Two Sum

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have *exactly* one solution, and you may not use the same element twice.

You can return the answer in any order.

Example 1:

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Output: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2:

Input: nums = [3,2,4], target = 6
Output: [1,2]

Example 3:

Input: nums = [3,3], target = 6
Output: [0,1]

Constraints:

  • 2 <= nums.length <= 104

  • -109 <= nums[i] <= 109

  • -109 <= target <= 109

  • Only one valid answer exists.

Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity?

std::vector<int> twoSum(std::vector<int>& nums, int target) {
    std::vector<int> res;
    if (nums.empty()) {
        return res;
    }

    std::unordered_map<int, int> imap;
    int idx = 0;
    for (const auto i : nums) {
        int sup = target - i;
        if (imap.count(sup) != 0) {
            res.push_back(imap[sup]);
            res.push_back(idx);
        }
        imap.emplace(i, idx);
        idx++;
    }
    return  res;
}
  • 11 - 20

# Title Solution Acceptance Difficulty Frequency
20 Valid Parentheses 35.7% Easy
21 Merge Two Sorted Lists 45.5% Easy
22 Generate Parentheses 52.8% Medium
23 Merge k Sorted Lists 32.6% Hard
31 Next Permutation 30.0% Medium
32 Longest Valid Parentheses 24.8% Hard
33 Search in Rotated Sorted Array 32.6% Medium
34 Find First and Last Position of Element in Sorted Array 32.8% Medium
39 Combination Sum 46.3% Medium
42 Trapping Rain Water 41.5% Hard
  • 21 - 30

# Title Solution Acceptance Difficulty Frequency
46 Permutations 53.0% Medium
48 Rotate Image 46.4% Medium
49 Group Anagrams 44.3% Medium
53 Maximum Subarray 42.6% Easy
55 Jump Game 31.1% Medium
56 Merge Intervals 34.6% Medium
62 Unique Paths 46.1% Medium
64 Minimum Path Sum 45.2% Medium
70 Climbing Stairs 43.2% Easy
72 Edit Distance 36.2% Hard
  • 31 - 40

# Title Solution Acceptance Difficulty Frequency
75 Sort Colors 41.1% Medium
76 Minimum Window Substring 29.6% Hard
78 Subsets 50.5% Medium
79 Word Search 30.2% Medium
84 Largest Rectangle in Histogram 30.1% Hard
85 Maximal Rectangle 32.2% Hard
94 Binary Tree Inorder Traversal 54.7% Medium
96 Unique Binary Search Trees 44.8% Medium
98 Validate Binary Search Tree 25.1% Medium
101 Symmetric Tree 42.5% Easy
  • 41 - 50

# Title Solution Acceptance Difficulty Frequency
102 Binary Tree Level Order Traversal 46.7% Medium
104 Maximum Depth of Binary Tree 58.9% Easy
105 Construct Binary Tree from Preorder and Inorder Traversal 39.1% Medium
114 Flatten Binary Tree to Linked List 40.8% Medium
121 Best Time to Buy and Sell Stock 46.0% Easy
124 Binary Tree Maximum Path Sum 29.1% Hard
128 Longest Consecutive Sequence 40.7% Hard
136 Single Number 58.7% Easy
139 Word Break 34.1% Medium
141 Linked List Cycle 35.5% Easy
  • 51 - 60

# Title Solution Acceptance Difficulty Frequency
142 Linked List Cycle II 30.7% Medium
146 LRU Cache 23.7% Hard
148 Sort List 33.6% Medium
152 Maximum Product Subarray 28.4% Medium
155 Min Stack 35.3% Easy
160 Intersection of Two Linked Lists 31.9% Easy
169 Majority Element 51.2% Easy
198 House Robber 40.7% Easy
200 Number of Islands 40.0% Medium
206 Reverse Linked List 52.3% Easy
  • 61 - 70

# Title Solution Acceptance Difficulty Frequency
207 Course Schedule 36.4% Medium
208 Implement Trie (Prefix Tree) 36.4% Medium
215 Kth Largest Element in an Array 45.5% Medium
221 Maximal Square 32.1% Medium
226 Invert Binary Tree 56.8% Easy
234 Palindrome Linked List 35.2% Easy
236 Lowest Common Ancestor of a Binary Tree 35.0% Medium
238 Product of Array Except Self 53.6% Medium
239 Sliding Window Maximum 36.8% Hard
240 Search a 2D Matrix II 40.1% Medium
  • 71 - 80

# Title Solution Acceptance Difficulty Frequency
253 Meeting Rooms II 41.9% Medium
279 Perfect Squares 40.4% Medium
283 Move Zeroes 53.4% Easy
287 Find the Duplicate Number 48.0% Medium
297 Serialize and Deserialize Binary Tree 39.0% Hard
300 Longest Increasing Subsequence 40.1% Medium
301 Remove Invalid Parentheses 38.2% Hard
309 Best Time to Buy and Sell Stock with Cooldown 43.4% Medium
312 Burst Balloons 46.0% Hard
322 Coin Change 28.8% Medium
  • 81 - 90

# Title Solution Acceptance Difficulty Frequency
337 House Robber III 47.1% Medium
338 Counting Bits 63.8% Medium
347 Top K Frequent Elements 53.1% Medium
394 Decode String 43.6% Medium
406 Queue Reconstruction by Height 58.7% Medium
416 Partition Equal Subset Sum 39.7% Medium
437 Path Sum III 41.8% Easy
438 Find All Anagrams in a String 36.1% Easy
448 Find All Numbers Disappeared in an Array 52.6% Easy
461 Hamming Distance 70.0% Easy
  • 91 - 100

# Title Solution Acceptance Difficulty Frequency
494 Target Sum 44.8% Medium
538 Convert BST to Greater Tree 49.8% Easy
543 Diameter of Binary Tree 46.1% Easy
560 Subarray Sum Equals K 41.5% Medium
572 Subtree of Another Tree 41.1% Easy
581 Shortest Unsorted Continuous Subarray 29.6% Easy
617 Merge Two Binary Trees 69.0% Easy
621 Task Scheduler 44.1% Medium
647 Palindromic Substrings 55.5% Medium
771 Jewels and Stones 82.6% Easy

出现频度为5

  1. Leet Code OJ 1. Two Sum [Difficulty: Easy]

  2. Leet Code OJ 8. String to Integer (atoi) [Difficulty: Easy]

  3. Leet Code OJ 15. 3Sum [Difficulty: Medium]

  4. Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]

  5. Leet Code OJ 21. Merge Two Sorted Lists [Difficulty: Easy]

  6. Leet Code OJ 28. Implement strStr() [Difficulty: Easy]

  7. Leet Code OJ 56. Merge Intervals [Difficulty: Hard]

  8. Leet Code OJ 57. Insert Interval [Difficulty: Hard]

  9. Leet Code OJ 65. Valid Number [Difficulty: Hard]

  10. Leet Code OJ 70. Climbing Stairs [Difficulty: Easy]

  11. Leet Code OJ 73. Set Matrix Zeroes [Difficulty: Medium]

  12. Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]

  13. Leet Code OJ 98. Validate Binary Search Tree [Difficulty: Medium]

  14. Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]

  15. Leet Code OJ 127. Word Ladder [Difficulty: Medium]

出现频度为4

  1. Leet Code OJ 2. Add Two Numbers [Difficulty: Medium]

  2. Leet Code OJ 12. Integer to Roman

  3. Leet Code OJ 13. Roman to Integer

  4. Leet Code OJ 22. Generate Parentheses

  5. Leet Code OJ 23. Merge k Sorted Lists

  6. Leet Code OJ 24. Swap Nodes in Pairs

  7. Leet Code OJ 27. Remove Element [Difficulty: Easy]

  8. Leet Code OJ 46. Permutations

  9. Leet Code OJ 49. Anagrams

  10. Leet Code OJ 67. Add Binary

  11. Leet Code OJ 69. Sqrt(x)

  12. Leet Code OJ 77. Combinations

  13. Leet Code OJ 78. Subsets

  14. Leet Code OJ 79. Word Search

  15. Leet Code OJ 91. Decode Ways [Difficulty: Medium]

  16. Leet Code OJ 102. Binary Tree Level Order Traversal [Difficulty: Easy]

  17. Leet Code OJ 129. Sum Root to Leaf Numbers

  18. Leet Code OJ 131. Palindrome Partitioning