Leetcode 算法题解

本页面是博主leetcode题解集合

  • 最左侧是题AC的情况,打勾的表示已经AC(目前无锁的题全部AC)
  • Title栏目下有链接的就是已经发题解的了,有的题没有写题解,有空的时候补上。
  • 如果要哪一个我还没发的 leetcode题解报告 ,可以留言,博主抽空就写。
  • 有任何疑问欢迎留言^ ^ 博主尽快回复

注:318题以后,Acceptance为博主AC的时候的通过率,之前的为2015.12.18的通过率

下面是解题报告~:

# Title Acceptance Difficulty Language
 √ 403 Frog Jump 35.7% Hard  Python
 √ 402 Remove K Digits 20.2% Medium  Python
 √ 401 Binary Watch 37.3% Easy  Python
 √ 400 Nth Digit 22.6% Easy  Python
 √ 399 Evaluate Division 34.2% Medium  Python
 √ 398 Random Pick Index 30.6% Medium  Python
 √ 397 Integer Replacement 25.9% Easy  Python
 √ 396 Rotate Function 28.4% Easy  Python
 √ 395 Longest Substring with At Least K Repeating Characters 32.6% Medium  C++ / Python
 √ 394 Decode String 38.7% Medium  Python
 √ 393 UTF-8 Validation 33.1% Medium  Python
 √ 392 Is Subsequence 44.0% Medium  Python
 √ 391 Perfect Rectangle 16.9% Hard  Python
 √ 390 Elimination Game 15.1% Medium  Python
 √ 389 Find the Difference 49.0% Easy  Python
 √ 388 Longest Absolute File Path 13.2% Medium Python
 √ 387 First Unique Character in a String 32% Easy Python
 √ 386 Lexicographical Numbers 13.1% Medium Python
 √ 385 Mini Parser 4.4 % Medium Python
 √ 384 Shuffle an Array 37.8 % Medium C++ / Java / Python
 √ 383 Ransom Note 47.2 % Easy C++ / Java / Python
 √ 382 Linked List Random Node 45.6 % Medium C++ / Java / Python
 √ 381 Insert Delete GetRandom O(1) – Duplicates allowed 30.4 % Medium C++ / Python
 √ 380 Insert Delete GetRandom O(1) 33.8 % Medium Python
 √ 378 Kth Smallest Element in a Sorted Matrix 43.1% Medium C++/ Java / Python
 √ 377 Combination Sum IV 41.6% Medium C++/ Java / Python
 √ 376 Wiggle Subsequence 44% Medium C++/ Java / Python
 √ 375 Guess Number Higher or Lower II 36.4% Medium C++/ Java / Python
 √ 374 Guess Number Higher or Lower 31.2% Easy C++/ Java / Python
 √ 373 Find K Pairs with Smallest Sums 25.7% Medium C++
 √ 372 Super Pow 24.9% Medium C++/ Java / Python
 √ 371 Sum of Two Integers 50.7% Easy C++/ Java / Python
 √ 368 Largest Divisible Subset 31% Medium C++/ Java / Python
 √ 367 Valid Perfect Square 23% Medium C++/ Java / Python
 √ 365 Water and Jug Problem 23% Medium C++/ Java / Python
 √ 363 Max Sum of Rectangle No Larger Than K 19.2% Hard C++
 √ 357 Count Numbers with Unique Digits 36.7% Medium C++/ Java / Python
 √ 355 Design Twitter  26.2 % Hard Python
 √ 354 Russian Doll Envelopes  26.2 % Hard C++ / Python
 √ 352 Data Stream as Disjoint Intervals  34 % Hard  Java
 √ 350 Intersection of Two Arrays II  44.2 % Easy Python
 √ 349 Intersection of Two Arrays  46 % Easy Python
 √ 347 Top K Frequent Elements  44.1 % Medium C++ / Python
 √ 345 Reverse Vowels of a String  35.1 % Easy  C++
 √ 344 Reverse String  60 % Easy  C++ / Python
 √ 343 Integer Break  35.5 % Medium   Python
 √ 342 Power of Four  35.5 % Easy  C++/ Java / Python
 √ 341 Flatten Nested List Iterator  17 % Medium
 √ 338 Counting Bits  55.7 % Medium  C++/ Java / Python
 √ 337 House Robber III  32.8 % Medium  C++/ Java / Python
 √ 336 Palindrome Pairs  15.4 % Hard  Python
 √ 335 Self Crossing  10.9 % Medium  C++/ Java / Python
 √ 334 Increasing Triplet Subsequence  34 % Medium  C++/ Java / Python
 √ 332 Reconstruct Itinerary  14 % Medium  C++/ Python
 √ 331 Verify Preorder Serialization of a Binary Tree  36 % Medium   Java / Python
 √ 330 Patching Array  21 % Medium  C++ / Java / python
 √ 329 Longest Increasing Path in a Matrix  25.3 % Medium  C++ / Java / Python
 √ 328 Odd Even Linked List  44 % Easy  C++ / Java / Python
 √ 327 Count of Range Sum 23.6 % Hard  C++ / Python
 √ 326 Power of Three 36.3 % Easy  C++ / Python
 √ 324 Wiggle Sort II 17.8 % Medium  java / Python
 √ 322 Coin Change 25 % Medium C++ / Java / Python
 √ 321 Create Maximum Number 1 % Hard  C++ / Java / Python
 √ 319 Bulb Switcher 40.4% Medium  C++ / Java / Python
 √ 318 Maximum Product of Word Lengths 35.6% Medium  C++ / Java / Python
 √ 316 Remove Duplicate Letters 19.2% Medium Python
 √ 315 Count of Smaller Numbers After Self 24.4% Hard
 √ 313 Super Ugly Number 29.3% Medium
 √ 312 Burst Balloons 29.0% Hard
 √ 310 Minimum Height Trees 24.1% Medium
 √ 309 Best Time to Buy and Sell Stock with Cooldown 34.0% Medium
 √ 307 Range Sum Query – Mutable 15.7% Medium
 √ 306 Additive Number 23.3% Medium
 √ 304 Range Sum Query 2D – Immutable 20.5% Medium
 √ 303 Range Sum Query – Immutable 23.8% Easy
 √ 301 Remove Invalid Parentheses 28.7% Hard
 √ 300 Longest Increasing Subsequence 31.9% Medium
 √ 299 Bulls and Cows 26.2% Easy
 √ 297 Serialize and Deserialize Binary Tree 24.4% Medium
 √ 295 Find Median from Data Stream 19.8% Hard
 √ 292 Nim Game 50.1% Easy
 √ 290 Word Pattern 27.2% Easy
 √ 289 Game of Life 32.3% Medium
 √ 287 Find the Duplicate Number 36.1% Hard
 √ 284 Peeking Iterator 31.9% Medium
 √ 283 Move Zeroes 42.4% Easy
 √ 282 Expression Add Operators 21.6% Hard
 √ 279 Perfect Squares 29.9% Medium
 √ 278 First Bad Version 21.1% Easy
 √ 275 H-Index II 31.8% Medium  Python
 √ 274 H-Index 27.2% Medium   C++ / Python
 √ 273 Integer to English Words 16.9% Medium
 √ 268 Missing Number 37.6% Medium  C++ / Python
 √ 264 Ugly Number II 24.7% Medium
 √ 263 Ugly Number 34.7% Easy
 √ 260 Single Number III 40.9% Medium
 √ 258 Add Digits 47.6% Easy  C++ / Python
 √ 257 Binary Tree Paths 25.1% Easy
 √ 242 Valid Anagram 39.2% Easy
 √ 241 Different Ways to Add Parentheses 30.7% Medium
 √ 240 Search a 2D Matrix II 31.5% Medium  C++/ Java / Python
 √ 239 Sliding Window Maximum 24.9% Hard
 √ 238 Product of Array Except Self 39.7% Medium
 √ 237 Delete Node in a Linked List 43.9% Easy
 √ 236 Lowest Common Ancestor of a Binary Tree 27.7% Medium  python
 √ 235 Lowest Common Ancestor of a Binary Search Tree 37.9% Easy  python
 √ 234 Palindrome Linked List 25.4% Easy
 √ 233 Number of Digit One 22.7% Medium
 √ 232 Implement Queue using Stacks 33.9% Easy
 √ 231 Power of Two 33.4% Easy
 √ 230 Kth Smallest Element in a BST 34.1% Medium
 √ 229 Majority Element II 24.3% Medium
 √ 228 Summary Ranges 21.7% Easy
 √ 227 Basic Calculator II 22.3% Medium
 √ 226 Invert Binary Tree 42.2% Easy
 √ 225 Implement Stack using Queues 30.3% Easy
 √ 224 Basic Calculator 19.6% Medium
 √ 223 Rectangle Area 28.1% Easy
 √ 222 Count Complete Tree Nodes 23.1% Medium
 √ 221 Maximal Square 21.8% Medium
 √ 220 Contains Duplicate III 17.4% Medium
 √ 219 Contains Duplicate II 28.0% Easy
 √ 218 The Skyline Problem 19.5% Hard
 √ 217 Contains Duplicate 39.1% Easy
 √ 216 Combination Sum III 32.5% Medium
 √ 215 Kth Largest Element in an Array 29.9% Medium
 √ 214 Shortest Palindrome 18.2% Hard
 √ 213 House Robber II 28.7% Medium
 √ 212 Word Search II 17.0% Hard
 √ 211 Add and Search Word – Data structure design 20.2% Medium
 √ 210 Course Schedule II 20.5% Medium
 √ 209 Minimum Size Subarray Sum 25.2% Medium
 √ 208 Implement Trie (Prefix Tree) 24.8% Medium
 √ 207 Course Schedule 24.5% Medium
 √ 206 Reverse Linked List 36.4% Easy
 √ 205 Isomorphic Strings 27.3% Easy
 √ 204 Count Primes 22.2% Easy
 √ 203 Remove Linked List Elements 26.9% Easy
 √ 202 Happy Number 34.6% Easy
 √ 201 Bitwise AND of Numbers Range 28.0% Medium
 √ 200 Number of Islands 25.3% Medium
 √ 199 Binary Tree Right Side View 31.2% Medium
 √ 198 House Robber 32.1% Easy
 √ 191 Number of 1 Bits 37.8% Easy
 √ 190 Reverse Bits 29.2% Easy
 √ 189 Rotate Array 19.6% Easy
 √ 188 Best Time to Buy and Sell Stock IV 20.5% Hard
 √ 187 Repeated DNA Sequences 22.7% Medium
 √ 179 Largest Number 17.5% Medium
 √ 174 Dungeon Game 19.5% Hard
 √ 173 Binary Search Tree Iterator 32.0% Medium
 √ 172 Factorial Trailing Zeroes 30.8% Easy
 √ 171 Excel Sheet Column Number 39.0% Easy
 √ 169 Majority Element 38.4% Easy
 √ 168 Excel Sheet Column Title 19.9% Easy
 √ 166 Fraction to Recurring Decimal 14.0% Medium
 √ 165 Compare Version Numbers 16.3% Easy
 √ 164 Maximum Gap 25.5% Hard
 √ 162 Find Peak Element 32.5% Medium
 √ 160 Intersection of Two Linked Lists 29.8% Easy  c / python
 √ 155 Min Stack 20.9% Easy
 √ 154 Find Minimum in Rotated Sorted Array II 33.2% Hard
 √ 153 Find Minimum in Rotated Sorted Array 34.7% Medium
 √ 152 Maximum Product Subarray 20.9% Medium
 √ 151 Reverse Words in a String 15.4% Medium
 √ 150 Evaluate Reverse Polish Notation 22.4% Medium
 √ 149 Max Points on a Line 13.7% Hard
 √ 148 Sort List 23.5% Medium
 √ 147 Insertion Sort List 27.9% Medium
 √ 146 LRU Cache 15.5% Hard
 √ 145 Binary Tree Postorder Traversal 33.9% Hard
 √ 144 Binary Tree Preorder Traversal 38.0% Medium
 √ 143 Reorder List 21.8% Medium
 √ 142 Linked List Cycle II 31.5% Medium
 √ 141 Linked List Cycle 36.6% Medium
 √ 140 Word Break II 18.6% Hard
 √ 139 Word Break 23.9% Medium
 √ 138 Copy List with Random Pointer 25.7% Hard
 √ 137 Single Number II 36.2% Medium
 √ 136 Single Number 47.5% Medium
 √ 135 Candy 21.5% Hard
 √ 134 Gas Station 26.5% Medium
 √ 133 Clone Graph 24.5% Medium
 √ 132 Palindrome Partitioning II 20.8% Hard
 √ 131 Palindrome Partitioning 27.3% Medium
 √ 130 Surrounded Regions 15.3% Medium
 √ 129 Sum Root to Leaf Numbers 31.3% Medium
 √ 128 Longest Consecutive Sequence 30.7% Hard
 √ 127 Word Ladder 19.5% Medium
 √ 126 Word Ladder II 13.4% Hard
 √ 125 Valid Palindrome 22.8% Easy
 √ 124 Binary Tree Maximum Path Sum 22.3% Hard
 √ 123 Best Time to Buy and Sell Stock III 25.1% Hard
 √ 122 Best Time to Buy and Sell Stock II 40.3% Medium
 √ 121 Best Time to Buy and Sell Stock 34.4% Medium
 √ 120 Triangle 28.7% Medium
 √ 119 Pascal’s Triangle II 30.6% Easy
 √ 118 Pascal’s Triangle 31.6% Easy
 √ 117 Populating Next Right Pointers in Each Node II 32.3% Hard
 √ 116 Populating Next Right Pointers in Each Node 36.3% Medium
 √ 115 Distinct Subsequences 27.7% Hard
 √ 114 Flatten Binary Tree to Linked List 29.8% Medium
 √ 113 Path Sum II 27.2% Medium
 √ 112 Path Sum 30.3% Easy
 √ 111 Minimum Depth of Binary Tree 29.7% Easy
 √ 110 Balanced Binary Tree 32.8% Easy
 √ 109 Convert Sorted List to Binary Search Tree 29.1% Medium
 √ 108 Convert Sorted Array to Binary Search Tree 35.5% Medium
 √ 107 Binary Tree Level Order Traversal II 32.2% Easy
 √ 106 Construct Binary Tree from Inorder and Postorder Traversal 27.8% Medium
 √ 105 Construct Binary Tree from Preorder and Inorder Traversal 27.2% Medium
 √ 104 Maximum Depth of Binary Tree 46.5% Easy
 √ 103 Binary Tree Zigzag Level Order Traversal 27.3% Medium
 √ 102 Binary Tree Level Order Traversal 30.7% Easy
 √ 101 Symmetric Tree 32.6% Easy
 √ 100 Same Tree 42.3% Easy
 √ 99 Recover Binary Search Tree 25.3% Hard
 √ 98 Validate Binary Search Tree 20.4% Medium
 √ 97 Interleaving String 21.6% Hard
 √ 96 Unique Binary Search Trees 36.2% Medium
 √ 95 Unique Binary Search Trees II 28.9% Medium
 √ 94 Binary Tree Inorder Traversal 37.8% Medium
 √ 93 Restore IP Addresses 22.1% Medium
 √ 92 Reverse Linked List II 26.7% Medium
 √ 91 Decode Ways 16.8% Medium
 √ 90 Subsets II 29.0% Medium
 √ 89 Gray Code 34.4% Medium
 √ 88 Merge Sorted Array 29.4% Easy
 √ 87 Scramble String 25.5% Hard
 √ 86 Partition List 28.3% Medium
 √ 85 Maximal Rectangle 22.7% Hard
 √ 84 Largest Rectangle in Histogram 23.3% Hard
 √ 83 Remove Duplicates from Sorted List 35.5% Easy
 √ 82 Remove Duplicates from Sorted List II 25.8% Medium
 √ 81 Search in Rotated Sorted Array II 31.4% Medium
 √ 80 Remove Duplicates from Sorted Array II 31.4% Medium
 √ 79 Word Search 21.6% Medium
 √ 78 Subsets 29.6% Medium
 √ 77 Combinations 32.4% Medium
 √ 76 Minimum Window Substring 20.0% Hard
 √ 75 Sort Colors 33.5% Medium
 √ 74 Search a 2D Matrix 32.6% Medium
 √ 73 Set Matrix Zeroes 32.4% Medium
 √ 72 Edit Distance 27.4% Hard
 √ 71 Simplify Path 20.9% Medium
 √ 70 Climbing Stairs 35.5% Easy
 √ 69 Sqrt(x) 24.2% Medium
 √ 68 Text Justification 15.4% Hard  c++ / python
 √ 67 Add Binary 25.7% Easy
 √ 66 Plus One 31.8% Easy
 √ 65 Valid Number 11.8% Hard
 √ 64 Minimum Path Sum 33.4% Medium
 √ 63 Unique Paths II 28.6% Medium
 √ 62 Unique Paths 34.6% Medium
 √ 61 Rotate List 22.1% Medium
 √ 60 Permutation Sequence 23.8% Medium
 √ 59 Spiral Matrix II 33.2% Medium
 √ 58 Length of Last Word 28.1% Easy
 √ 57 Insert Interval 22.6% Hard
 √ 56 Merge Intervals 23.8% Hard
 √ 55 Jump Game 27.5% Medium
 √ 54 Spiral Matrix 21.5% Medium
 √ 53 Maximum Subarray 35.5% Medium
 √ 52 N-Queens II 37.6% Hard
 √ 51 N-Queens 26.2% Hard
 √ 50 Pow(x, n) 27.4% Medium
 √ 49 Group Anagrams 25.5% Medium
 √ 48 Rotate Image 33.2% Medium
 √ 47 Permutations II 26.7% Medium
 √ 46 Permutations 33.6% Medium
 √ 45 Jump Game II 24.6% Hard
 √ 44 Wildcard Matching 16.4% Hard
 √ 43 Multiply Strings 22.1% Medium
 √ 42 Trapping Rain Water 31.0% Hard
 √ 41 First Missing Positive 23.2% Hard
 √ 40 Combination Sum II 26.3% Medium
 √ 39 Combination Sum 29.3% Medium
 √ 38 Count and Say 26.9% Easy
 √ 37 Sudoku Solver 23.4% Hard
 √ 36 Valid Sudoku 28.7% Easy
 √ 35 Search Insert Position 36.3% Medium
 √ 34 Search for a Range 28.0% Medium
 √ 33 Search in Rotated Sorted Array 29.3% Hard
 √ 32 Longest Valid Parentheses 21.7% Hard
 √ 31 Next Permutation 25.5% Medium
 √ 30 Substring with Concatenation of All Words 20.1% Hard
 √ 29 Divide Two Integers 15.2% Medium
 √ 28 Implement strStr() 23.6% Easy
 √ 27 Remove Element 32.4% Easy
 √ 26 Remove Duplicates from Sorted Array 32.0% Easy
 √ 25 Reverse Nodes in k-Group 26.3% Hard
 √ 24 Swap Nodes in Pairs 33.6% Medium
 √ 23 Merge k Sorted Lists 22.1% Hard
 √ 22 Generate Parentheses 34.5% Medium
 √ 21 Merge Two Sorted Lists 33.8% Easy
 √ 20 Valid Parentheses 27.8% Easy
 √ 19 Remove Nth Node From End of List 27.9% Easy
 √ 18 4Sum 22.5% Medium
 √ 17 Letter Combinations of a Phone Number 26.9% Medium
 √ 16 3Sum Closest 27.8% Medium
 √ 15 3Sum 17.6% Medium
 √ 14 Longest Common Prefix 26.6% Easy
 √ 13 Roman to Integer 36.7% Easy
 √ 12 Integer to Roman 36.1% Medium
 √ 11 Container With Most Water 33.0% Medium
 √ 10 Regular Expression Matching 21.2% Hard
 √ 9 Palindrome Number 30.0% Easy
 √ 8 String to Integer (atoi) 13.1% Easy
 √ 7 Reverse Integer 23.5% Easy
 √ 6 ZigZag Conversion 22.5% Easy
 √ 5 Longest Palindromic Substring 21.7% Medium
 √ 4 Median of Two Sorted Arrays 17.7% Hard
 √ 3 Longest Substring Without Repeating Characters 21.0% Medium
 √ 2 Add Two Numbers 21.5% Medium
 √ 1 Two Sum 19.8% Medium

您的支持将鼓励我继续创作!

22 thoughts on “Leetcode 算法题解

  1. 博主好! 最近也在刷leetcode!
    今天看了一道 shortest palindrome 还是不太明白怎么用KMP的!
    想问一下具体的步骤哇!

  2. 博主威武,

    麻烦博主有空发一下Majority Element II的题解吧。那题不太好理解为什么那个所谓的voting algorithm works。

    ShadowGiraffe

Leave a Reply

Your email address will not be published. Required fields are marked *