Leetcode - Java 一、电子书(pdf) Latex排版整理的电子书 Backtracking [Graph] (https://github.com/dingjikerbo/leetcode/blob/master/ebook/graph/leetcode-graph.pdf) 二、文档列表 刷题要点总结 Facebook面试总结 Bitset技巧 Map新接口 题目分类 三、所有题目列表 # Title Solution Score Backup 1 Two Sum Java 100 2 Add Two Numbers Java 80 3 Longest Substring Without Repeating Characters Java 这个系列的所有题都要多做几遍 4 Median of Two Sorted Arrays Java 70 这题很经典,多做几遍 5 Longest Palindromic Substring Java 85 这题对比动态规划和最优算法 6 ZigZag Conversion Java 7 Reverse Integer Java 95 8 String to Integer (atoi) Java 90 很考代码能力,容易错 9 Palindrome Number Java 10 Regular Expression Matching Java 60 这题很经典,多做几遍,和#44一起 11 Container With Most Water Java 12 Integer to Roman Java 13 Roman to Integer Java 14 Longest Common Prefix Java 15 3Sum Java 70 16 3Sum Closest Java 17 Letter Combinations of a Phone Number Java 85 18 4Sum Java 19 Remove Nth Node From End of List Java 20 Valid Parentheses Java 100 21 Merge Two Sorted Lists Java 90 22 Generate Parentheses Java 80 这题看两遍 23 Merge k Sorted Lists Java 70 24 Swap Nodes in Pairs Java 25 Reverse Nodes in k-Group Java 80 26 Remove Duplicates from Sorted Array Java 80 27 Remove Element Java 28 Implement strStr() Java 70 29 Divide Two Integers Java 30 Substring with Concatenation of All Words Java 31 Next Permutation Java 32 Longest Valid Parentheses Java 33 Search in Rotated Sorted Array Java 80 34 Search for a Range Java 35 Search Insert Position Java 36 Valid Sudoku Java 80 37 Sudoku Solver Java 70 这道题是典型的back tracking,多做几遍 38 Count and Say Java 80 39 Combination Sum Java 70 排列组合系列的题要多做几遍 40 Combination Sum II Java 70 41 First Missing Positive Java 42 Trapping Rain Water Java 95 43 Multiply Strings Java 80 44 Wildcard Matching Java 60 和#10多做几遍 45 Jump Game II Java 46 Permutations Java 47 Permutations II Java 70 多做几遍 48 Rotate Image Java 100 49 Group Anagrams Java 95 50 Pow(x, n) Java 80 51 N-Queens Java 52 N-Queens II Java 53 Maximum Subarray Java 95 55 Jump Game Java 56 Merge Intervals Java 70 57 Insert Interval Java 75 这题要多做几遍 60 Permutation Sequence Java 70 这题思路巧妙,多做两遍 66 Plus One Java 100 这题多看一遍 67 Add Binary Java 100 68 Text Justification Java 69 Sqrt(x) Java 85 71 Simplify Path Java 80 72 Edit Distance Java 75 73 Set Matrix Zeroes Java 90 74 Search a 2D Matrix Java 75 Sort Colors Java 65 这题多做几遍,很有意思 76 Minimum Window Substring Java 50 这题以及类似的题一定要多做几遍,很经典,参见window 77 Combinations Java 78 Subsets Java 85 79 Word Search Java 85 80 Remove Duplicates from Sorted Array II Java 100 81 Search in Rotated Sorted Array II Java 70 82 Remove Duplicates from Sorted List II Java 75 83 Remove Duplicates from Sorted List Java 100 84 Largest Rectangle in Histogram Java 70 85 Maximal Rectangle Java 75 88 Merge Sorted Array Java 100 90 Subsets II Java 80 91 Decode Ways Java 75 这题多做几遍,包括#639 93 Restore IP Addresses Java 80 多看两遍 94 Binary Tree Inorder Traversal Java 100 95 Unique Binary Search Trees II Java 70 多做几遍,递归和DP 96 Unique Binary Search Trees Java 80 98 Validate Binary Search Tree Java 85 注意溢出 99 Recover Binary Search Tree Java 60 这题很容易错,要多做几遍 100 Same Tree Java 100 101 Symmetric Tree Java 95 102 Binary Tree Level Order Traversal Java 85 103 Binary Tree Zigzag Level Order Traversal Java 80 104 Maximum Depth of Binary Tree Java 100 105 Construct Binary Tree from Preorder and Inorder Traversal Java 95 106 Construct Binary Tree from Inorder and Postorder Traversal Java 90 107 Binary Tree Level Order Traversal II Java 100 108 Convert Sorted Array to Binary Search Tree Java 100 110 Balanced Binary Tree Java 80 111 Minimum Depth of Binary Tree Java 80 112 Path Sum Java 85 113 Path Sum II Java 65 错了好几次,得多做几遍 114 Flatten Binary Tree to Linked List Java 80 116 Populating Next Right Pointers in Each Node Java 80 117 Populating Next Right Pointers in Each Node II Java 80 119 Pascal's Triangle II Java 80 121 Best Time to Buy and Sell Stock Java 100 122 Best Time to Buy and Sell Stock II Java 100 123 Best Time to Buy and Sell Stock III Java 75 124 Binary Tree Maximum Path Sum Java 60 125 Valid Palindrome Java 100 126 Word Ladder II Java 127 Word Ladder Java 70 此题非常经典,务必连同ii多做几遍,将双端BFS吃透 128 Longest Consecutive Sequence Java 60 129 Sum Root to Leaf Numbers Java 60 这题错了几次,多做几遍 130 Surrounded Regions Java 65 131 Palindrome Partitioning Java 132 Palindrome Partitioning II Java 133 Clone Graph Java 70 这题不难,多看两遍,BFS方法再做两遍 138 Copy List with Random Pointer Java 95 有一个易错点 139 Word Break Java 80 多看两遍 140 Word Break II Java 75 这题多做两遍,很典型 141 Linked List Cycle Java 75 144 Binary Tree Preorder Traversal Java 85 145 Binary Tree Postorder Traversal Java 80 146 LRU Cache Java 95 好题目,多做几遍 149 Max Points on a Line Java 60 151 Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/description/) Java 70 这题虽然不难,但是也错了几次 152 Maximum Product Subarray Java 153 Find Minimum in Rotated Sorted Array Java 154 Find Minimum in Rotated Sorted Array II Java 155 Min Stack Java 95 156 Binary Tree Upside Down Java 70 这道题挺有意思,多做几遍 157 Read N Characters Given Read4 Java 80 这题多做几遍,结合#158 158 Read N Characters Given Read4 II - Call multiple times Java 70 159 Longest Substring with At Most Two Distinct Characters Java 100 多看两遍 160 Intersection of Two Linked Lists Java 100 161 One Edit Distance Java 85 和#72做两遍 163 Missing Ranges Java 65 多做几遍,太容易错了 164 Maximum Gap Java 65 167 Two Sum II - Input array is sorted Java 100 168 Excel Sheet Column Title Java 170 Two Sum III - Data structure design Java 100 这道题再多做一遍 171 Excel Sheet Column Number Java 172 Factorial Trailing Zeroes Java 100 173 Binary Search Tree Iterator Java 70 多留意一下 179 Largest Number Java 90 186 Reverse Words in a String II Java 90 188 Best Time to Buy and Sell Stock IV Java 190 Reverse Bits Java 85 198 House Robber Java 80 199 Binary Tree Right Side View Java 80 200 Number of Islands Java 85 这道题很经典,而且方法不止一种,每种方法都多做几遍,包括UF,#305 203 Remove Linked List Elements Java 204 Count Primes Java 85 206 Reverse Linked List Java 90 207 Course Schedule Java 100 典型的拓扑排序 208 Implement Trie (Prefix Tree) Java 80 和#211多留意,trie很典型 209 Minimum Size Subarray Sum Java 85 210 Course Schedule II Java 95 211 Add and Search Word - Data structure design Java 85 212 Word Search II Java 213 House Robber II Java 80 214 Shortest Palindrome Java 215 Kth Largest Element in an Array Java 65 这题很经典,三种解法都要了然于胸 216 Combination Sum III Java 65 217 Contains Duplicate Java 100 218 The Skyline Problem Java 60 这题多做两遍 219 Contains Duplicate II Java 95 220 Contains Duplicate III Java 65 221 Maximal Square Java 80 222 Count Complete Tree Nodes Java 70 一般的做法会超时 223 Rectangle Area Java 95 225 Implement Stack using Queues Java 90 226 Invert Binary Tree Java 80 230 Kth Smallest Element in a BST Java 85 注意Follow Up 232 Implement Queue using Stacks Java 95 233 Number of Digit One Java 234 Palindrome Linked List Java 75 235 Lowest Common Ancestor of a Binary Search Tree Java 100 236 Lowest Common Ancestor of a Binary Tree Java 50 这题很经典,多做几遍,留意节点不在树中的情况 238 Product of Array Except Self Java 85 239 Sliding Window Maximum Java 75 这题非常经典,多做几遍,包括常规算法(优先队列,treemap)及优化算法双端队列 240 Search a 2D Matrix II Java 100 241 Different Ways to Add Parentheses Java 242 Valid Anagram Java 100 243 Shortest Word Distance Java 80 246 Strobogrammatic Number Java 70 #247一个系列,多看两遍 247 Strobogrammatic Number II Java 70 多看两遍 250 Count Univalue Subtrees Java 70 这题要多做几遍 251 Flatten 2D Vector Java 100 252 Meeting Rooms Java 100 253 Meeting Rooms II Java 90 254 Factor Combinations Java 80 255 Verify Preorder Sequence in Binary Search Tree Java 85 很简单,粗心错了 256 Paint House Java 95 257 Binary Tree Paths Java 80 259 3Sum Smaller Java 95 这题虽然简单,但是因为思维定式还是错了几次 261 Graph Valid Tree Java 70 这题多做几遍 263 Ugly Number Java 85 264 Ugly Number II Java 70 265 Paint House II Java 60 266 Palindrome Permutation Java 100 267 Palindrome Permutation II Java 80 典型,多看两遍 269 Alien Dictionary Java 70 这题要多做几遍 270 Closest Binary Search Tree Value Java 90 271 Encode and Decode Strings Java 65 思路巧妙,多看几遍 272 Closest Binary Search Tree Value II Java 60 这题非常值得多做几遍,几种写法都试试 273 Integer to English Words Java 75 多做几遍,做到bug free 274 H-Index Java 80 275 H-Index II Java 75 277 Find the Celebrity Java 100 278 First Bad Version Java 100 279 Perfect Squares Java 95 280 Wiggle Sort Java 80 思路巧妙,多看两遍 281 Zigzag Iterator Java 85 多做三遍,考虑扩展到k的情况 282 Expression Add Operators Java 50 283 Move Zeroes Java 100 284 Peeking Iterator Java 100 285 Inorder Successor in BST Java 70 这道题有意思,要多做几遍 286 Walls and Gates Java 70 多看两遍 287 Find the Duplicate Number Java 288 Unique Word Abbreviation Java 70 这题不难,多做两遍,题目意思容易理解错 293 Flip Game Java 90 294 Flip Game II Java 90 295 Find Median from Data Stream Java 297 Serialize and Deserialize Binary Tree Java 80 好题目,多做做,递归的非递归的 298 Binary Tree Longest Consecutive Sequence Java 70 多做三遍,尽可能简洁 300 Longest Increasing Subsequence Java 301 Remove Invalid Parentheses Java 70 比较难,多做几遍 303 Range Sum Query - Immutable Java 100 304 Range Sum Query 2D - Immutable Java 65 305 Number of Islands II Java 70 这题多做几遍,经典的UF 307 Range Sum Query - Mutable Java 70 和#303, #304, #308定要多做几遍,掌握BIT 308 Range Sum Query 2D - Mutable Java 70 309 Best Time to Buy and Sell Stock with Cooldown Java 310 Minimum Height Trees Java 60 这题多做几遍 311 Sparse Matrix Multiplication Java 80 312 Burst Balloons Java 60 314 Binary Tree Vertical Order Traversal Java 80 315 Count of Smaller Numbers After Self Java 60 316 Remove Duplicate Letters Java 70 317 Shortest Distance from All Buildings Java 75 典型的bfs,多做两遍 319 Bulb Switcher Java 90 320 Generalized Abbreviation Java 70 这题是典型的back tracking,多做几遍 323 Number of Connected Components in an Undirected Graph Java 90 典型的图,多看两遍 324 Wiggle Sort II Java 60 325 Maximum Size Subarray Sum Equals k Java 75 这题思路有意思,多做几遍 328 Odd Even Linked List Java 90 329 Longest Increasing Path in a Matrix Java 70 这题要多做几遍 333 Largest BST Subtree Java 50 这道题虽然不难,但是折腾了很久,一定要多做 334 Increasing Triplet Subsequence Java 75 335 Self Crossing Java 80 336 Palindrome Pairs Java 337 House Robber III Java 70 建议再做两遍 339 Nested List Weight Sum Java 340 Longest Substring with At Most K Distinct Characters Java 80 和#159类似 341 Flatten Nested List Iterator Java 75 这题有点意思,多做两遍 345 Reverse Vowels of a String Java 100 346 Moving Average from Data Stream Java 95 347 Top K Frequent Elements Java 85 351 Android Unlock Patterns Java 70 这题多做几遍 357 Count Numbers with Unique Digits Java 358 Rearrange String k Distance Apart Java 359 Logger Rate Limiter Java 100 这题如果不考虑空间消耗的话其实很简单 361 Bomb Enemy Java 65 这题多做几遍,开始没思路 364 Nested List Weight Sum II Java 366 Find Leaves of Binary Tree Java 60 这道题刚开始还没思路 374 Guess Number Higher or Lower Java 100 375 Guess Number Higher or Lower II Java 60 377 Combination Sum IV Java 65 380 Insert Delete GetRandom O(1) Java 75 这道题很有意思,多做几遍 381 Insert Delete GetRandom O(1) - Duplicates allowed Java 382 Linked List Random Node Java 384 Shuffle an Array Java 75 387 First Unique Character in a String Java 100 388 Longest Absolute File Path Java 65 其实不难,乍看没思路,多做几遍 391 Perfect Rectangle Java 70 这题很trick,多做两遍 393 UTF-8 Validation Java 60 错了很多次,多做几遍 394 Decode String Java 75 这题容易错,多做四遍 395 Longest Substring with At Least K Repeating Characters Java 65 398 Random Pick Index Java 80 399 Evaluate Division Java 60 这题多做几遍 401 Binary Watch Java 404 Sum of Left Leaves Java 80 406 Queue Reconstruction by Height Java 60 这题开始没思路,多做几遍 407 Trapping Rain Water II Java 408 Valid Word Abbreviation Java 80 多做两遍 409 Longest Palindrome Java 410 Split Array Largest Sum Java 412 Fizz Buzz Java 100 413 Third Maximum Number Java 80 418 Sentence Screen Fitting Java 65 这题思路巧妙,多做几遍,常规思路超时 422 Valid Word Square Java 90 425 Word Squares Java 70 这题很典型,多做几遍 437 Path Sum III Java 60 这道题错了很多遍,要重点关注 438 Find All Anagrams in a String Java 75 这道题非常经典,最优解法需要多做几遍,保证once bug free 449 Serialize and Deserialize BST Java 90 和#297一样 450 Delete Node in a BST Java 60 这题非常经典,值得多做十遍 477 Total Hamming Distance Java 482 License Key Formatting Java 90 501 Find Mode in Binary Search Tree Java 70 不难,容易错,多做两次 508 Most Frequent Subtree Sum Java 513 Find Bottom Left Tree Value Java 100 515 Find Largest Value in Each Tree Row Java 100 526 Beautiful Arrangement Java 80 535 Encode and Decode TinyURL Java 100 637 Average of Levels in Binary Tree Java 100 652 Find Duplicate Subtrees Java 70 开始还没思路