LeetCode 题解 # Title Solution 1 两数之和 Two Sum Rust, Go, Python, Js 2 Add Two Numbers 3 Longest Substring Without Repeating Characters 4 Median of Two Sorted Arrays 5 Longest Palindromic Substring 6 ZigZag Conversion 7 Reverse Integer 8 String to Integer (atoi) 9 Palindrome Number 10 Regular Expression Matching 11 盛最多水的容器 Container With Most Water Rust 12 Integer to Roman 13 Roman to Integer 14 Longest Common Prefix 15 三数之和 3Sum Rust 16 3Sum Closest 17 Letter Combinations of a Phone Number 18 4Sum 19 Remove Nth Node From End of List 20 Valid Parentheses 21 Merge Two Sorted Lists 22 Generate Parentheses 23 Merge k Sorted Lists 24 两两交换链表中的节点 Swap Nodes in Pairs Rust 25 K 个一组翻转链表 Reverse Nodes in k-Group Rust 26 Remove Duplicates from Sorted Array 27 Remove Element 28 Implement strStr() 29 Divide Two Integers 30 Substring with Concatenation of All Words 31 Next Permutation 32 Longest Valid Parentheses 33 Search in Rotated Sorted Array 34 Search for a Range 35 Search Insert Position 36 Valid Sudoku 37 Sudoku Solver 38 Count and Say 39 Combination Sum 40 Combination Sum II 41 First Missing Positive 42 Trapping Rain Water 43 Multiply Strings 44 Wildcard Matching 45 Jump Game II 46 Permutations 47 Permutations II 48 Rotate Image 49 Group Anagrams 50 "Pow(x, n)" 51 N-Queens 52 N-Queens II 53 Maximum Subarray 54 Spiral Matrix 55 Jump Game 56 Merge Intervals 57 Insert Interval 58 Length of Last Word 59 Spiral Matrix II 60 Permutation Sequence 61 Rotate List 62 Unique Paths 63 Unique Paths II 64 Minimum Path Sum 65 Valid Number 66 Plus One 67 Add Binary 68 Text Justification 69 Sqrt(x) 70 爬楼梯 Climbing Stairs Rust 71 Simplify Path 72 Edit Distance 73 Set Matrix Zeroes 74 Search a 2D Matrix 75 Sort Colors 76 Minimum Window Substring 77 Combinations 78 Subsets 79 Word Search 80 Remove Duplicates from Sorted Array II 81 Search in Rotated Sorted Array II 82 Remove Duplicates from Sorted List II 83 Remove Duplicates from Sorted List 84 Largest Rectangle in Histogram 85 Maximal Rectangle 86 Partition List 87 Scramble String 88 Merge Sorted Array 89 Gray Code 90 Subsets II 91 Decode Ways 92 Reverse Linked List II 93 Restore IP Addresses 94 Binary Tree Inorder Traversal 95 Unique Binary Search Trees II 96 Unique Binary Search Trees 97 交错字符串 Interleaving String Rust, Go 98 Validate Binary Search Tree 99 Recover Binary Search Tree 100 Same Tree 101 Symmetric Tree 102 Binary Tree Level Order Traversal 103 Binary Tree Zigzag Level Order Traversal 104 Maximum Depth of Binary Tree 105 Construct Binary Tree from Preorder and Inorder Traversal 106 Construct Binary Tree from Inorder and Postorder Traversal 107 Binary Tree Level Order Traversal II 108 Convert Sorted Array to Binary Search Tree 109 Convert Sorted List to Binary Search Tree 110 Balanced Binary Tree 111 Minimum Depth of Binary Tree 112 Path Sum 113 Path Sum II 114 Flatten Binary Tree to Linked List 115 Distinct Subsequences 116 Populating Next Right Pointers in Each Node 117 Populating Next Right Pointers in Each Node II 118 Pascal's Triangle 119 Pascal's Triangle II 120 Triangle 121 Best Time to Buy and Sell Stock 122 Best Time to Buy and Sell Stock II 123 Best Time to Buy and Sell Stock III 124 Binary Tree Maximum Path Sum 125 Valid Palindrome 126 Word Ladder II 127 Word Ladder 128 Longest Consecutive Sequence 129 Sum Root to Leaf Numbers 130 Surrounded Regions 131 Palindrome Partitioning 132 Palindrome Partitioning II 133 Clone Graph 134 Gas Station 135 Candy 136 Single Number 137 Single Number II 138 Copy List with Random Pointer 139 Word Break 140 Word Break II 141 环形链表 Linked List Cycle Rust 142 环形链表 II Linked List Cycle II 143 Reorder List 144 Binary Tree Preorder Traversal 145 Binary Tree Postorder Traversal 146 LRU Cache 147 Insertion Sort List 148 Sort List 149 Max Points on a Line 150 Evaluate Reverse Polish Notation 151 Reverse Words in a String 152 Maximum Product Subarray 153 Find Minimum in Rotated Sorted Array 154 Find Minimum in Rotated Sorted Array II 155 Min Stack 156 Binary Tree Upside Down 157 Read N Characters Given Read4 158 Read N Characters Given Read4 II - Call multiple times 159 Longest Substring with At Most Two Distinct Characters 160 Intersection of Two Linked Lists 161 One Edit Distance 162 Find Peak Element 163 Missing Ranges 164 Maximum Gap 165 Compare Version Numbers 166 Fraction to Recurring Decimal 167 Two Sum II - Input array is sorted 168 Excel Sheet Column Title 169 Majority Element 170 Two Sum III - Data structure design 171 Excel Sheet Column Number 172 Factorial Trailing Zeroes 173 Binary Search Tree Iterator 174 Dungeon Game 179 Largest Number 186 Reverse Words in a String II 187 Repeated DNA Sequences 188 Best Time to Buy and Sell Stock IV 189 Rotate Array 190 Reverse Bits 191 Number of 1 Bits 198 House Robber 199 Binary Tree Right Side View 200 Number of Islands 201 Bitwise AND of Numbers Range 202 Happy Number 203 Remove Linked List Elements 204 Count Primes 205 Isomorphic Strings 206 反转链表 Reverse Linked List Rust 207 Course Schedule 208 Implement Trie (Prefix Tree) 209 Minimum Size Subarray Sum 210 Course Schedule II 211 Add and Search Word - Data structure design 212 Word Search II 213 House Robber II 214 Shortest Palindrome 215 Kth Largest Element in an Array 216 Combination Sum III 217 Contains Duplicate 218 The Skyline Problem 219 Contains Duplicate II 220 Contains Duplicate III 221 Maximal Square 222 Count Complete Tree Nodes 223 Rectangle Area 224 Basic Calculator 225 Implement Stack using Queues 226 Invert Binary Tree 227 Basic Calculator II 228 Summary Ranges 229 Majority Element II 230 Kth Smallest Element in a BST 231 Power of Two 232 Implement Queue using Stacks 233 Number of Digit One 234 Palindrome Linked List 235 Lowest Common Ancestor of a Binary Search Tree 236 Lowest Common Ancestor of a Binary Tree 237 Delete Node in a Linked List 238 Product of Array Except Self 239 Sliding Window Maximum 240 Search a 2D Matrix II 241 Different Ways to Add Parentheses 242 Valid Anagram 257 Binary Tree Paths 258 Add Digits 260 Single Number III 263 Ugly Number 264 Ugly Number II 268 Missing Number 273 Integer to English Words 274 H-Index 275 H-Index II 278 First Bad Version 279 Perfect Squares 282 Expression Add Operators 283 移动零 Move Zeroes Rust 284 Peeking Iterator 285 Inorder Successor in BST 287 Find the Duplicate Number 289 Game of Life 290 Word Pattern 292 Nim Game 295 Find Median from Data Stream 297 Serialize and Deserialize Binary Tree 299 Bulls and Cows 300 Longest Increasing Subsequence 301 Remove Invalid Parentheses 303 Range Sum Query - Immutable 304 Range Sum Query 2D - Immutable 306 Additive Number 307 Range Sum Query - Mutable 309 Best Time to Buy and Sell Stock with Cooldown 310 Minimum Height Trees 312 戳气球 Burst Balloons Rust 313 Super Ugly Number 315 Count of Smaller Numbers After Self 316 Remove Duplicate Letters 318 Maximum Product of Word Lengths 319 Bulb Switcher 321 Create Maximum Number 322 Coin Change 324 Wiggle Sort II 326 Power of Three 327 Count of Range Sum 328 Odd Even Linked List 329 Longest Increasing Path in a Matrix 330 Patching Array 331 Verify Preorder Serialization of a Binary Tree 332 Reconstruct Itinerary 334 Increasing Triplet Subsequence 336 Palindrome Pairs 337 House Robber III 338 Counting Bits 341 扁平化嵌套列表迭代器 Flatten Nested List Iterator Rust 342 Power of Four 343 Integer Break 344 Reverse String 345 Reverse Vowels of a String 347 Top K Frequent Elements 349 Intersection of Two Arrays 350 Intersection of Two Arrays II 357 Count Numbers with Unique Digits 367 Valid Perfect Square 371 Sum of Two Integers 376 Wiggle Subsequence 377 Combination Sum IV 380 Insert Delete GetRandom O(1) 381 Insert Delete GetRandom O(1) - Duplicates allowed 382 Linked List Random Node 383 Ransom Note 384 Shuffle an Array 385 Mini Parser 386 Lexicographical Numbers 387 First Unique Character in a String 388 Longest Absolute File Path 389 Find the Difference 390 Elimination Game 391 Perfect Rectangle 392 Is Subsequence 393 UTF-8 Validation 394 Decode String 395 Longest Substring with At Least K Repeating Characters 396 Rotate Function 397 Integer Replacement 398 Random Pick Index 399 Evaluate Division 400 Nth Digit 401 Binary Watch 402 Remove K Digits 403 Frog Jump 404 Sum of Left Leaves 405 Convert a Number to Hexadecimal 406 Queue Reconstruction by Height 409 Longest Palindrome 410 Split Array Largest Sum 412 Fizz Buzz 413 Arithmetic Slices 414 Third Maximum Number 415 Add Strings 416 Partition Equal Subset Sum 418 SentenceScreenFitting 437 Path Sum III 438 Find all Anagrams in a string 449 Serialize and Deserialize BST 450 DeleteNodeInABST 463 Island Perimeter 477 Total Hamming Distance 509 Fibonacci Number 518 Coin Change 2 520 Detect Capital 532 K-diff Pairs in an Array 538 Convert BST to Greater Tree 543 Diameter of Binary Tree 547 Friend Circles 563 Binary Tree Tilt 572 Subtree of Another Tree 581 Shortest Unsorted Continuous Subarray 623 Add One Row to Tree 628 Maximum Product of Three Numbers 643 Maximum Average Subarray I 647 Palindromic Substrings 652 Find Duplicate Subtrees 655 Print Binary Tree 661 Image Smoother 662 Maximum Width of Binary Tree 665 Non-decreasing Array 671 Second Minimum Node In a Binary Tree 674 Longest Continuous Increasing Subsequence 684 Redundant Connection 687 Longest Univalue Path 695 Max Area of Island 712 Minimum ASCII Delete Sum for Two Strings 714 Best Time to Buy and Sell Stock with Transaction Fee 717 1-bit and 2-bit Characters 721 Accounts Merge 746 Min Cost Climbing Stairs 747 Largest Number At Least Twice of Others 771 Jewels and Stones 804 Unique Morse Code Words 830 Positions of Large Groups 837 Most Common Word 844 Backspace String Compare 849 Maximize Distance to Closest Person 852 Peak Index in a Mountain Array 858 Mirror Reflection 859 Buddy Strings 876 Middle of the Linked List 905 Sort Array By Parity 914 X of a Kind in a Deck of Cards 922 Sort Array By Parity II 931 Minimum Falling Path Sum 941 Valid Mountain Array 950 Reveal Cards In Increasing Order 951 Flip Equivalent Binary Trees 958 Check Completeness of a Binary Tree 961 N-Repeated element in size 2N Array 969 Pancake Sorting 971 Flip Binary Tree To Match Preorder Traversal 976 Largest Perimeter Triangle 977 Squares of a Sorted Array 978 Longest Turbulent Subarray 979 Distribute Coins in Binary Tree 980 Unique Paths III 981 Time Based Key-Value Store 983 Minimum Cost For Tickets 984 String Without AAA or BBB 985 Sum of Even Numbers After Queries 986 Interval List Intersections 987 Vertical Order Traversal of a Binary Tree 988 Smallest String Starting From Leaf 989 Add to Array-Form of Integer 990 Satisfiability of Equality Equations 991 Broken Calculator 993 Cousins in Binary Tree 1024 Video Stitching 1028 Recover a Tree From Preorder Traversal 1029 Two City Scheduling 1030 Matrix Cells in Distance Order 1170 Compare Strings by Frequency of the Smallest Character 1207 Unique Number of Occurrences 1300 转变数组后最接近目标值的数组和 Rust, Python