If you like this project, please give me a star. ★
###If you feel benefited from Leetcode and loves it, please consider to donate to Leetcode in order to help us build the best OJ platform.
Your ideas/fixes/algorithms are more than welcome!
1. Fork this repo
2. Clone your forked repo (`git clone https://github.com/YOUR_GITHUB_USERNAME/Leetcode.git`) onto your local machine
3. `cd` into your cloned directory, create your feature branch (`git checkout -b my-awesome-fix`)
4. `git add` your desired changes to this repo
5. Commit your changes (`git commit -m 'Added some awesome features/fixes'`)
6. Push to the branch (`git push origin my-awesome-feature`)
7. Open your forked repo on Github website, create a new Pull Request to this repo!
# | Title | Solutions | Time | Space | Difficulty | Tag | Notes |
---|---|---|---|---|---|---|---|
660 | Remove 9 | Solution | O(n) | O(1) | Hard | Math | |
659 | Split Array into Consecutive Subsequences | Solution | O(n) | O(n) | Medium | HashMap | |
658 | Find K Closest Elements | Solution | O(n) | O(1) | Medium | ||
657 | Judge Route Circle | Solution | O(n) | O(1) | Easy | ||
656 | Coin Path | Solution | O(n*B) | O(n) | Hard | DP | |
655 | Print Binary Tree | Solution | O(h*2^h) | O(h*2^h) | Medium | Recursion | |
654 | Maximum Binary Tree | Solution | O(n^2) | O(n) | Medium | Tree | |
653 | Two Sum IV - Input is a BST | Solution | Easy | Tree | |||
652 | Find Duplicate Subtrees | Solution | O(n) | O(n) | Medium | Tree | |
651 | 4 Keys Keyboard | Solution | O(n^2) | O(n) | Medium | DP | |
650 | 2 Keys Keyboard | Solution | O(n^2) | O(n) | Medium | DP | |
649 | Dota2 Senate | Solution | O(n) | O(n) | Medium | Greedy | |
648 | Replace Words | Solution | O(n) | O(n) | Medium | Trie | |
647 | Palindromic Substrings | Solution | O(n^2) | O(1) | Medium | DP | |
646 | Maximum Length of Pair Chain | Solution | O(nlogn) | O(1) | Medium | DP | |
645 | Set Mismatch | Solution | O(nlogn) | O(1) | Easy | ||
644 | Maximum Average Subarray II | Solution | O(1) | Hard | Binary Search | ||
643 | Maximum Average Subarray I | Solution | O(n) | O(1) | Easy | ||
642 | Design Search Autocomplete System | Solution | O(n) | O(n) | Hard | Design | |
640 | Solve the Equation | Solution | O(n) | O(n) | Medium | ||
639 | Decode Ways II | Solution | O(n) | O(n) | Hard | DP | |
638 | Shopping Offers | Solution | O(2^n) | O(n) | Medium | DP, DFS | |
637 | Average of Levels in Binary Tree | Solution | O(n) | O(1) | Easy | ||
636 | Exclusive Time of Functions | Solution | O(n) | O(n/2) | Medium | Stack | |
635 | Design Log Storage System | Solution | O(n) | O(1) | Medium | Design | |
634 | Find the Derangement of An Array | Solution | O(n) | O(1) | Medium | Math | |
633 | Sum of Square Numbers | Solution | O(logn) | O(1) | Easy | Binary Search | |
632 | Smallest Range | Solution | O(n*logk) | O(k) | Hard | Heap | |
631 | Design Excel Sum Formula | Solution | Hard | Design, Topological Sort | |||
630 | Course Schedule III | Solution | O(n*logn) | O(n) | Hard | Heap, Greedy | |
629 | K Inverse Pairs Array | Solution | O(n*k) | O(n*k) | Hard | DP | |
628 | Maximum Product of Three Numbers | Solution | O(nlogn) | O(1) | Easy | ||
625 | Minimum Factorization | Solution | O(?) | O(?) | Medium | ||
624 | Maximum Distance in Arrays | Solution | O(nlogn) | O(1) | Easy | Sort, Array | |
623 | Add One Row to Tree | Solution | O(n) | O(h) | Medium | Tree | |
621 | Task Scheduler | Solution | O(n) | O(26) | Medium | Greedy, Queue | |
617 | Merge Two Binary Trees | Solution | O(n) | O(h) | Easy | Tree, Recursion | |
616 | Add Bold Tag in String | Solution | O(n*k) (n is length of string, k is size of dict) | O(n) | Medium | String | |
611 | Valid Triangle Number | Solution | O(n^2logn) | O(logn) | Medium | Binary Search | |
609 | Find Duplicate File in System | Solution | O(n*x) (x is the average length of each string) | O(n*x) | Medium | HashMap | |
606 | Construct String from Binary Tree | Solution | O(n) | O(n) | Easy | Tree, Recursion | |
605 | Can Place Flowers | Solution | O(n) | O(1) | Easy | Array | |
604 | Design Compressed String Iterator | Solution | O(n) | O(n) | Easy | Design, String | |
600 | Non-negative Integers without Consecutive Ones | Solution | O(log2(max_int) = 32) | O(log2(max_int) = 32) | Hard | Bit Manipulation, DP | |
599 | Minimum Index Sum of Two Lists | Solution | O(max(m,n)) | O(max(m,n)) | Easy | HashMap | |
598 | Range Addition II | Solution | O(n) (n is the number of operations) | O(1) | Easy | ||
594 | Longest Harmonious Subsequence | Solution | O(n) | O(n) | Easy | Array, HashMap | |
593 | Valid Square | Solution | O(1) | O(1) | Medium | Math | |
592 | Fraction Addition and Subtraction | Solution | O(nlogx) | O(n) | Medium | Math | |
591 | Tag Validator | Solution | O(n) | O(n) | Hard | Stack, String | |
588 | Design In-Memory File System | Solution | O(n) | O(h) | Hard | Trie, Design | |
587 | Erect the Fence | Solution | O(?) | O(?) | Hard | Geometry | |
583 | Delete Operation for Two Strings | Solution | O(m*n) | O(m*n) could be optimized to O(n) | Medium | DP | |
582 | Kill Process | Solution | O(n) | O(h) | Medium | Stack | |
581 | Shortest Unsorted Continuous Subarray | Solution | O(n) | O(1) | Easy | Array, Sort | |
576 | Out of Boundary Paths | Solution | O(Nmn) | O(m*n) | Hard | DP, DFS | |
575 | Distribute Candies | Solution | O(nlogn) | O(1) | Easy | Array | |
573 | Squirrel Simulation | Solution | O(n) | O(1) | Medium | Math | |
572 | Subtree of Another Tree | Solution | O(m*n) | O(1) | Easy | Tree | |
568 | Maximum Vacation Days | Solution | O(n^2*k) | O(n*k) | Hard | DP | |
567 | Permutation in String | Solution | O(max(m,n)) | O(1) | Medium | Sliding Windows, Two Pointers | |
566 | Reshape the Matrix | Solution | O(m*n) | O(1) | Easy | ||
565 | Array Nesting | Solution | O(n) | O(n) | Medium | ||
563 | Binary Tree Tilt | Solution | O(n) | O(n) | Easy | Tree Recursion | |
562 | Longest Line of Consecutive One in Matrix | Solution | O(m*n) | O(m*n) | Medium | Matrix DP | |
561 | Array Partition I | Solution | O(nlogn) | O(1) | Easy | Array | |
560 | Subarray Sum Equals K | Solution | O(n) | O(n) | Medium | Array, HashMap | |
557 | Reverse Words in a String III | Solution | O(n) | O(n) | Easy | String | |
556 | Next Greater Element III | Solution | O(n) | O(1) | Medium | String | |
555 | Split Concatenated Strings | Solution | O(n^2) | O(n) | Medium | String | |
554 | Brick Wall | Solution | O(n) (n is total number of bricks in the wall) | O(m) (m is width of the wall) | Medium | HashMap | |
553 | Optimal Division | Solution | O(n) | O(n) | Medium | String, Math | |
552 | Student Attendance Record II | Solution | O(n) | O(1) | Hard | DP | |
551 | Student Attendance Record I | Solution | O(n) | O(1) | Easy | String | |
549 | Binary Tree Longest Consecutive Sequence II | Solution | O(n) | O(n) | Medium | Tree | |
548 | Split Array with Equal Sum | Solution | O(n^2) | O(1) | Medium | Array | |
547 | Friend Circles | Solution | O(n^2) | O(n) | Medium | Union Find | |
546 | Remove Boxes | Solution | O(n^3) | O(n^3) | Hard | DFS, DP | |
545 | Boundary of Binary Tree | Solution | O(n) | O(n) | Medium | Recursion | |
544 | Output Contest Matches | Solution | O(n) | O(n) | Medium | Recursion | |
543 | Diameter of Binary Tree | Solution | O(n) | O(h) | Easy | Tree/DFS/Recursion | |
542 | 01 Matrix | Solution | O(m*n) | O(n) | Medium | BFS | |
541 | Reverse String II | Solution | O(n) | O(1) | Easy | String | |
540 | Single Element in a Sorted Array | Solution | O(n) | O(1) | Medium | ||
539 | Minimum Time Difference | Solution | O(n) | O(1) | Medium | String | |
538 | Convert BST to Greater Tree | Solution | O(n) | O(h) | Medium | Tree | |
537 | Complex Number Multiplication | Solution | O(1) | O(1) | Medium | Math, String | |
536 | Construct Binary Tree from String | Solution | O(n) | O(h) | Medium | Recursion, Stack | |
535 | Encode and Decode TinyURL | Solution | O(1) | O(n) | Medium | Design | |
533 | Lonely Pixel II | Solution | O(m*n) | O(m) (m is number of rows) | Medium | HashMap | |
532 | K-diff Pairs in an Array | Solution | O(n) | O(n) | Easy | HashMap | |
531 | Lonely Pixel I | Solution | O(m*n) | O(1) | Medium | ||
530 | Minimum Absolute Difference in BST | Solution | O(n) | O(n) | Easy | DFS | |
529 | Minesweeper | Solution | O(m*n) | O(k) | Medium | BFS | |
527 | Word Abbreviation | Solution | O(n^2) | O(n) | Hard | ||
526 | Beautiful Arrangement | Solution | O(n) | O(h) | Medium | Backtracking | |
525 | Contiguous Array | Solution | O(n) | O(n) | Medium | HashMap | |
524 | Longest Word in Dictionary through Deleting | Solution | O(n) | O(n) | Medium | Sort | |
523 | Continuous Subarray Sum | Solution | O(n) | O(1) | Medium | DP | |
522 | Longest Uncommon Subsequence II | Solution | O(x*n^2) (x is average length of strings) | O(1) | Medium | ||
521 | Longest Uncommon Subsequence I | Solution | O(max(x,y)) (x and y are length of strings) | O(1) | Easy | ||
520 | Detect Capital | Solution | O(n) | O(1) | Easy | ||
517 | Super Washing Machines | Solution | Hard | DP | |||
516 | Longest Palindromic Subsequence | Solution | O(n^2) | O(n^2) | Medium | DP | |
515 | Find Largest Value in Each Tree Row | Solution | O(n) | O(k) | Medium | BFS | |
514 | Freedom Trail | Solution | O(?) | O(?) | Hard | DP | |
513 | Find Bottom Left Tree Value | Solution | O(n) | O(k) | Medium | BFS | |
508 | Most Frequent Subtree Sum | Solution | O(n) | O(n) | Medium | DFS, Tree | |
507 | Perfect Number | Solution | O(sqrt(n)) | O(1) | Easy | Math | |
506 | Relative Ranks | Solution | O(nlogn) | O(n) | Easy | ||
505 | The Maze II | Solution | O(m*n) | O(m*n) | Medium | BFS | |
504 | Base 7 | Solution | O(1) | O(1) | Easy | ||
503 | Next Greater Element II | Solution | O(n) | O(n) | Medium | Stack | |
502 | IPO | Solution | O(nlogn) | O(n) | Hard | Heap, Greedy | |
501 | Find Mode in Binary Tree | Solution | O(n) | O(k) | Easy | Binary Tree | |
500 | Keyboard Row | Solution | O(n) | O(1) | Easy | ||
499 | The Maze III | Solution | O(m*n) | O(m*n) | Hard | BFS | |
496 | Next Greater Element I | Solution | O(n*m) | O(1) | Easy | ||
498 | Diagonal Traverse | Solution | O(m*n) | O(1) | Medium | ||
495 | Teemo Attacking | Solution | O(n) | O(1) | Medium | Array | |
494 | Target Sum | Solution | O(2^n) | O(1) | Medium | ||
493 | Reverse Pairs | Solution | O(?) | O(?) | Hard | ||
492 | Construct the Rectangle | Solution | O(n) | O(1) | Easy | Array | |
491 | Increasing Subsequences | Solution | O(n!) | O(n) | Medium | Backtracking, DFS | |
490 | The Maze | Solution | O(m*n) | O(m*n) | Medium | BFS | |
488 | Zuma Game | Solution | O(?) | O(?) | Hard | DFS, Backtracking | |
487 | Max Consecutive Ones II | Solution | O(n) | O(n) | Medium | Array | |
486 | Predict the Winner | Solution | O(2^n) | O(n^2) | Medium | DP | |
485 | Max Consecutive Ones | Solution | O(n) | O(1) | Easy | Array | |
484 | Find Permutation | Solution | O(n) | O(1) | Medium | Array, String, Greedy | |
483 | Smallest Good Base | Solution | O(logn) | O(1) | Hard | Binary Search, Math | |
482 | License Key Formatting | Solution | O(n) | O(n) | Medium | ||
481 | Magical String | Solution | O(?) | O(?) | Medium | ||
480 | Sliding Window Median | Solution | O(nlogk) | O(k) | Hard | Heap | |
479 | Largest Palindrome Product | Solution | O(n) | O(1) | Easy | ||
477 | Total Hamming Distance | Solution | O(n) | O(1) | Medium | Bit Manipulation | |
476 | Number Complement | Solution | O(n) | O(1) | Easy | Bit Manipulation | |
475 | Heaters | Solution | max(O(nlogn), O(mlogn)) - m is the length of houses, n is the length of heaters | O(1) | Easy | Array Binary Search | |
474 | Ones and Zeroes | Solution | O(n) | O(m*n) | Medium | DP | |
473 | Matchsticks to Square | Solution | O(n!) | O(n) | Medium | Backtracking, DFS | |
472 | Concatenated Words | Solution | O(n^2) | O(n) | Hard | Trie, DP, DFS | |
471 | Encode String with Shortest Length | Solution | O(n^3) | O(n^2) | Hard | DP | |
469 | Convex Polygon | Solution | O(n) | O(1) | Medium | Math | |
468 | Validate IP Address | Solution | O(n) | O(1) | Medium | String | |
467 | Unique Substrings in Wraparound String | Solution | O(n) | O(1) | Medium | DP | |
466 | Count The Repetitions | Solution | O(max(m,n)) | O(1) | Hard | DP | |
465 | Optimal Account Balancing | Solution | Hard | DP | |||
464 | Can I Win | Solution | O(2^n) | O(n) | Medium | DP | |
463 | Island Perimeter | Solution | O(m*n) | O(1) | Easy | ||
462 | Minimum Moves to Equal Array Elements II | Solution | O(nlogn) | O(1) | Medium | ||
461 | Hamming Distance | Solution | O(n) | O(1) | Easy | ||
460 | LFU Cache | Solution | O(1) | O(n) | Hard | Design, LinkedHashMap, HashMap | |
459 | Repeated Substring Pattern | Solution | O(n) | O(n) | Easy | KMP | |
458 | Poor Pigs | Solution | O(1) | O(1) | Easy | Math | |
456 | 132 Pattern | Solution | O(n) | O(n) | Medium | Stack | |
455 | Assign Cookies | Solution | O(n) | O(1) | Easy | ||
454 | 4Sum II | Solution | O(n) | O(n) | Medium | HashMap | |
453 | Minimum Moves to Equal Array Elements | Solution | O(n) | O(1) | Easy | ||
452 | Minimum Number of Arrows to Burst Balloons | Solution | O(nlogn) | O(1) | Medium | Array, Greedy | |
451 | Sort Characters By Frequency | Solution | O(nlogn) | O(n) | Medium | HashMap | |
450 | Delete Node in a BST | Solution | O(?) | O(?) | Medium | Tree, Recursion | |
449 | Serialize and Deserialize BST | Solution | O(n) | O(h) | Medium | BFS | |
448 | Find All Numbers Disappeared in an Array | Solution | O(n) | O(1) | Easy | Array, HashMap | |
447 | Number of Boomerangs | Solution | O(n^2) | O(n) | Easy | HashMap | |
446 | Arithmetic Slices II - Subsequence | Solution | O(n^2) | O(n^2) | Hard | DP | |
445 | Add Two Numbers II | Solution | O(max(m,n) | O(max(m,n)) | Medium | Stack, LinkedList | |
444 | Sequence Reconstruction | Solution | O(n) | O(n) | Medium | Topological Sort, Graph | |
442 | Find All Duplicates in an Array | Solution | O(n) | O(1) | Medium | Array | |
441 | Arranging Coins | Solution | O(n) | O(1) | Easy | ||
440 | K-th Smallest in Lexicographical Order | Solution | O(n^2) | O(1) | Hard | ||
439 | Ternary Expression Parser | Solution | O(n) | O(n) | Medium | Stack | |
438 | Find All Anagrams in a String | Solution | O(n) | O(1) | Easy | Sliding Window | |
437 | Path Sum III | Solution | O(n^2) | O(n) | Easy | DFS, recursion | |
436 | Find Right Interval | Solution | O(nlogn) | O(n) | Medium | Binary Search | |
435 | Non-overlapping Intervals | Solution | O(nlogn) | O(1) | Medium | Greedy | |
434 | Number of Segments in a String | Solution | O(n) | O(1) | Easy | ||
432 | All O`one Data Structure | Solution | O(1) | O(n) | Hard | Design | |
425 | Word Squares | Solution | O(n!) | O(n) | Hard | Trie, Backtracking, Recursion | |
424 | Longest Repeating Character Replacement | Solution | O(n) | O(1) | Medium | Sliding Window | |
423 | Reconstruct Original Digits from English | Solution | O(n) | O(1) | Medium | Math | |
422 | Valid Word Square | Solution | O(n) | O(1) | Easy | ||
421 | Maximum XOR of Two Numbers in an Array | Solution | O(n) | O(1) | Medium | Bit Manipulation, Trie | |
420 | Strong Password Checker | Solution | ? | ? | Hard | ||
419 | Battleships in a Board | Solution | O(m*n) | O(1) | Medium | DFS | |
418 | Sentence Screen Fitting | Solution | O(n) | O(1) | Medium | ||
417 | Pacific Atlantic Water Flow | Solution | O(mnMax(m,n)) | O(m*n) | Medium | DFS | |
416 | Partition Equal Subset Sum | Solution | O(m*n) | O(m*n) | Medium | DP | |
415 | Add Strings | Solution | O(n) | O(1) | Easy | ||
414 | Third Maximum Number | Solution | O(n) | O(1) | Easy | ||
413 | Arithmetic Slices | Solution | O(n) | O(1) | Medium | DP | |
412 | Fizz Buzz | Solution | O(n) | O(1) | Easy | ||
411 | Minimum Unique Word Abbreviation | Solution | O(?) | O(?) | Hard | NP-Hard, Backtracking, Trie, Recursion | |
410 | Split Array Largest Sum | Solution | O(nlogn) | O(1) | Hard | Binary Search, DP | |
408 | Valid Word Abbreviation | Solution | O(n) | O(1) | Easy | ||
407 | Trapping Rain Water II | Solution | Hard | Heap | |||
406 | Queue Reconstruction by Height | Solution | O(nlogn) | O(1) | Medium | LinkedList, PriorityQueue | |
405 | Convert a Number to Hexadecimal | Solution | O(n) | O(1) | Easy | ||
404 | Sum of Left Leaves | Solution | O(n) | O(h) | Easy | ||
403 | Frog Jump | Solution | O(n^2) | O(n^2) | Hard | DP | |
402 | Remove K Digits | Solution | O(n) | O(n) | Medium | Greedy, Stack | |
401 | Binary Watch | Solution | O(1) | O(1) | Easy | ||
400 | Nth Digit | Solution | O(n) | O(1) | Easy | ||
399 | Evaluate Division | Solution | O(n*n!) | O(n) | Medium | Graph, DFS, Backtracking | |
398 | Random Pick Index | Solution | Medium | Reservoir Sampling | |||
397 | Integer Replacement | Solution | ? | ? | Easy | BFS | |
396 | Rotate Function | Solution | O(n^2) could be optimized to O(n) | O(1) | Easy | ||
393 | UTF-8 Validation | Solution | O(?) | O(?) | Medium | Bit Manipulation | |
392 | Is Subsequence | Solution | O(m*n) | O(1) | Medium | Array, String | |
391 | Perfect Rectangle | Solution | O(n) | O(1) | Hard | ||
390 | Elimination Game | Solution | O(logn) | O(1) | Medium | ||
389 | Find the Difference | Solution | O(n) | O(1) | Easy | ||
388 | Longest Absolute File Path | Solution | O(n) | O(d) | Medium | Stack | |
387 | First Unique Character in a String | Solution | O(n) | O(n) | Easy | HashMap | |
386 | Lexicographical Numbers | Solution | O(n) | O(1) | Medium | ||
385 | Mini Parser | Solution | O(n) | O(h) | Medium | Stack | |
384 | Shuffle an Array | Solution | O(n) | O(n) | Medium | ||
383 | Ransom Note | Solution | O(n) | O(n) | Medium | ||
382 | Linked List Random Node | Solution | O(1) | O(n) | Medium | Reservoir Sampling | |
381 | Insert Delete GetRandom O(1) - Duplicates allowed | Solution | Hard | ||||
380 | Insert Delete GetRandom O(1) | Solution | O(n) | O(1) | Medium | Design, HashMap | |
379 | Design Phone Directory | Solution | O(1) | O(n) | Medium | ||
377 | Combination Sum IV | Solution | O(?) | O(?) | Medium | ||
376 | Wiggle Subsequence | Solution | O(n) | O(1) | Medium | DP, Greedy | |
375 | Guess Number Higher or Lower II | Solution | O(n^2) | O(n^2) | Medium | DP | |
374 | Guess Number Higher or Lower | Solution | O(logn) | O(1) | Easy | Binary Search | |
373 | Find K Pairs with Smallest Sums | Solution | O(?) | O(?) | Medium | Heap | |
372 | Super Pow | Solution | O(n) | O(1) | Medium | Math | |
371 | Sum of Two Integers | Solution | O(n) | O(1) | Easy | ||
370 | Range Addition | Solution | O(n+k) | O(1) | Medium | ||
369 | Plus One Linked List | Solution | O(n) | O(1) | Medium | Linked List | |
368 | Largest Divisible Subset | Solution | O(n^2) | O(n) | Medium | DP | |
367 | Valid Perfect Square | Solution | O(n) | O(1) | Medium | ||
366 | Find Leaves of Binary Tree | Solution | O(n) | O(h) | Medium | DFS | |
365 | Water and Jug Problem | Solution | O(n) | O(1) | Medium | Math | |
364 | Nested List Weight Sum II | Solution | O(n) | O(h) | Medium | DFS | |
363 | Max Sum of Rectangle No Larger Than K | Solution | Hard | DP | |||
362 | Design Hit Counter | Solution | O(1) amortized | O(k) | Medium | Design | |
361 | Bomb Enemy | Solution | O(?) | O(?) | Medium | ||
360 | Sort Transformed Array | Solution | O(n) | O(1) | Medium | Two Pointers, Math | |
359 | Logger Rate Limiter | Solution | amortized O(1) | O(k) | Easy | HashMap | |
358 | Rearrange String k Distance Apart | Solution | O(n) | O(n) | Hard | HashMap, Heap, Greedy | |
357 | Count Numbers with Unique Digits | Solution | O(n) | O(1) | Medium | DP, Math | |
356 | Line Reflection | Solution | O(n) | O(n) | Medium | HashSet | |
355 | Design Twitter | Solution | O(n) | O(n) | Medium | Design, HashMap, Heap | |
354 | Russian Doll Envelopes | Solution | O(nlogn) | O(1) | Hard | DP, Binary Search | |
353 | Design Snake Game | Solution | O(?) | O(?) | Medium | ||
352 | Data Stream as Disjoint Intervals | Solution | O(logn) | O(n) | Hard | TreeMap | |
351 | Android Unlock Patterns | Solution | O(?) | O(?) | Medium | ||
350 | Intersection of Two Arrays II | Solution | O(m+n) | O((m+n)) could be optimized | Easy | HashMap, Binary Search | |
349 | Intersection of Two Arrays | Solution | O(m+n) | O(min(m,n)) | Easy | Two Pointers, Binary Search | |
348 | Design Tic-Tac-Toe | Solution | O(1) | O(n) | Medium | Design | |
347 | Top K Frequent Elements | Solution | O(n) | O(1) | Medium | HashTable, Heap | |
346 | Moving Average from Data Stream | Solution | O(1) | O(w)) | Easy | Queue | |
345 | Reverse Vowels of a String | Solution | O(n) | O(1) | Easy | String | |
344 | Reverse String | Solution | O(n) | O(1) | Easy | String | |
343 | Integer Break | Solution | O(1) | O(1) | Medium | Math | |
342 | Power of Four | Solution | O(n) | O(1) | Easy | Math | |
341 | Flatten Nested List Iterator | Solution | O(n) | O(n) | Medium | Stack | |
340 | Longest Substring with At Most K Distinct Characters | Solution | O(n) | O(1) | Hard | Sliding Window | |
339 | Nested List Weight Sum | Solution | O(n) | O(h)) | Easy | DFS | |
338 | Counting Bits | Solution | O(nlogn) | O(h) | Medium | ||
337 | House Robber III | Solution | O(n) | O(n) | Medium | DP | |
336 | Palindrome Pairs | Solution | O(n^2) | O(n) | Hard | ||
335 | Self Crossing | Solution | O(n) | O(1) | Hard | Math | |
334 | Increasing Triplet Subsequence | Solution | O(n^2) | O(1) | Medium | ||
333 | Largest BST Subtree | Solution | O(n) | O(n) | Medium | Tree | |
332 | Reconstruct Itinerary | Solution | O(n) | O(n) | Medium | Graph, DFS | |
331 | Verify Preorder Serialization of a Binary Tree | Solution | O(n) | O(n) | Medium | Stack | |
330 | Patching Array | Solution | O(m+logn) | O(1) | Hard | Greedy | |
329 | Longest Increasing Path in a Matrix | Solution | O(?) | O(?) | Hard | ||
328 | Odd Even Linked List | Solution | O(n) | O(1) | Medium | Linked List | |
327 | Count of Range Sum | Solution | O(?) | O(?) | Hard | ||
326 | Power of Three | Solution | O(1) | O(1) | Easy | Math | |
325 | Maximum Size Subarray Sum Equals k | Solution | O(n) | O(n) | Medium | Sort | |
324 | Wiggle Sort II | Solution | O(n) | O(n) | Medium | Sort | |
323 | Number of Connected Components in an Undirected Graph | Solution | O(?) | O(?) | Medium | ||
322 | Coin Change | Solution | O(?) | O(?) | Medium | ||
321 | Create Maximum Number | Solution | O(?) | O(?) | Hard | ||
320 | Generalized Abbreviation | Solution | O(n*2^n) | O(n) | Medium | Backtracking, Bit Manipulation | |
319 | Bulb Switcher | Solution | O(1) | O(1) | Medium | Brainteaser | |
318 | Maximum Product of Word Lengths | Solution | O(n^2) | O(n) | Medium | ||
317 | Shortest Distance from All Buildings | Solution | O(?) | O(?) | Hard | ||
316 | Remove Duplicate Letters | Solution | O(n) | O(1) | Hard | Stack, Recursion, Greedy | |
315 | Count of Smaller Numbers After Self | Solution | O(?) | O(?) | Hard | Tree | |
314 | Binary Tree Vertical Order Traversal | Solution | O(n) | O(n) | Medium | HashMap, BFS | |
313 | Super Ugly Number | Solution | O(?) | O(?) | Medium | ||
312 | Burst Balloons | Solution | O(?) | O(?) | Hard | DP | |
311 | Sparse Matrix Multiplication | Solution | O(mnl) | O(m*l) | Medium | ||
310 | Minimum Height Trees | Solution | ? | ? | Medium | ||
309 | Best Time to Buy and Sell Stock with Cooldown | Solution | O(n) | O(1) | Medium | DP | |
308 | Range Sum Query 2D - Mutable | Solution | ? | ? | Hard | Tree | |
307 | Range Sum Query - Mutable | Solution | ? | ? | Medium | Tree | |
306 | Additive Number | Solution | O(n^2) | O(n) | Medium | ||
305 | Number of Islands II | Solution | ? | ? | Hard | Union Find | |
304 | Range Sum Query 2D - Immutable | Solution | ? | ? | Medium | ||
303 | Range Sum Query - Immutable | Solution | O(n) | O(1) | Easy | ||
302 | Smallest Rectangle Enclosing Black Pixels | Solution | ? | O(m*n) | Hard | DFS, BFS | |
301 | Remove Invalid Parentheses | Solution | ? | ? | Hard | BFS | |
300 | Longest Increasing Subsequence | Solution | O(logn) | O(n) | Medium | DP | |
299 | Bulls and Cows | Solution | O(n) | O(1) | Easy | ||
298 | Binary Tree Longest Consecutive Sequence | Solution | O(n) | O(n) | Medium | Tree | |
297 | Serialize and Deserialize Binary Tree | Solution | O(n) | O(h) | Hard | BFS | |
296 | Best Meeting Point | Solution | ? | ? | Hard | ||
295 | Find Median from Data Stream | Solution | O(nlogn) | O(n) | Hard | Heap | |
294 | Flip Game II | Solution | O(?) | O(?) | Medium | Backtracking | |
293 | Flip Game | Solution | O(n) | O(1) | Easy | ||
292 | Nim Game | Solution | O(1) | O(1) | Easy | ||
291 | Word Pattern II | Solution | O(n) | O(n) | Hard | ||
290 | Word Pattern | Solution | O(n) | O(n) | Easy | ||
289 | Game of Life | Solution | O(m*n) | O(m*n), could be optimized to O(1) | Medium | ||
288 | Unique Word Abbreviation | Solution | O(n) | O(1) | Easy | ||
287 | Find the Duplicate Number | Solution | O(n) | O(1) | Medium | ||
286 | Walls and Gates | Solution | O(m*n) | O(g) | Medium | BFS | |
285 | Inorder Successor In BST | Solution | O(h) | O(1) | Medium | Tree | |
284 | Peeking Iterator | Solution | O(n) | O(n) | Medium | Design | |
283 | Move Zeroes | Solution | O(n) | O(1) | Easy | ||
282 | Expression Add Operators | Solution | O(?) | O(?) | Hard | ||
281 | Zigzag Iterator | Solution | O(n) | O(n) | Medium | ||
280 | Wiggle Sort | Solution | O(n) | O(1) | Medium | ||
279 | Perfect Squares | Solution | O(n) | O(1) | Medium | ||
278 | First Bad Version | Solution | O(logn) | O(1) | Easy | Binary Search | |
277 | Find the Celebrity | Solution | O(n) | O(1) | Medium | ||
276 | Paint Fence | Solution | O(n) | O(1) | Easy | DP | |
275 | H-Index II | Solution | O(logn) | O(1) | Medium | Binary Search | |
274 | H-Index | Solution | O(nlogn) | O(1) | Medium | ||
273 | Integer to English Words | Solution | O(n) | O(1) | Hard | Math, String | |
272 | Closest Binary Search Tree Value II | Solution | O(h+k) | O(h) | Hard | Stack | |
271 | Encode and Decode Strings | Solution | O(n) | O(1) | Medium | ||
270 | Closest Binary Search Tree Value | Solution | O(h) | O(1) | Easy | DFS | |
269 | Alien Dictionary | Solution | O(?) | O(?) | Hard | Topological Sort | |
268 | Missing Number | Solution | O(n) | O(1) | Easy | Bit Manipulation | |
267 | Palindrome Permutation II | Solution | O(n*n!) | O(n) | Medium | ||
266 | Palindrome Permutation | Solution | O(n) | O(1) | Easy | ||
265 | Paint House II | Solution | ? | ? | Hard | ||
264 | Ugly Number II | Solution | O(n) | O(n) | Medium | DP | |
263 | Ugly Number | Solution | O(n) | O(1) | Easy | ||
261 | Graph Valid Tree | Solution | O(V+E) | O(V+E) | Medium | ||
260 | Single Number III | Solution | O(n) | O(n) | Medium | ||
259 | 3Sum Smaller | Solution | O(n^2) | O(1) | Medium | ||
258 | Add Digits | Solution | O(1) | O(1) | Easy | ||
257 | Binary Tree Paths | Solution | O(n*h) | O(h) | DFS/Recursion | ||
256 | Paint House | Solution | O(n) | O(1) | Medium | DP | |
255 | Verify Preorder Sequence in Binary Search Tree | Solution | O(n) | O(h) | Medium | Tree | |
254 | Factor Combinations | Solution | O(nlogn) | O(nlogn) | Medium | Backtracking | |
253 | Meeting Rooms II | Solution | O(nlogn) | O(h) | Medium | Heap | |
252 | Meeting Rooms | Solution | O(nlogn) | O(1) | Easy | ||
251 | Flatten 2D Vector | Solution | O(1) | O(m*n) | Medium | ||
250 | Count Univalue Subtrees | Solution | O(n) | O(h) | Medium | DFS | |
249 | Group Shifted Strings | Solution | O(nlogn) | O(n) | |||
248 | Strobogrammatic Number III | Solution | O(?) | O(?) | Hard | Recursion, DFS | |
247 | Strobogrammatic Number II | Solution | O(n^2) | O(n) | Medium | Recursion | |
246 | Strobogrammatic Number | Solution | O(n) | O(1) | Easy | ||
245 | Shortest Word Distance III | Solution | O(n) | O(1) | Medium | ||
244 | Shortest Word Distance II | Solution | O(n) | O(n) | Medium | HashMap | |
243 | Shortest Word Distance | Solution | O(n) | O(1) | Easy | ||
242 | Valid Anagram | Solution | O(n) | O(1) | Easy | ||
241 | Different Ways to Add Parentheses | Solution | O(O(n * 4^n / n^(3/2))) | O(n * 4^n / n^(3/2)) | Medium | Divide and Conquer | |
240 | Search a 2D Matrix II | Solution | O(m+n) | O(1) | Medium | Binary Search | |
239 | Sliding Window Maximum | Solution | O(nlogn) | O(k) | Hard | Heap | |
238 | Product of Array Except Self | Solution | O(n) | O(1) | Medium | Array | |
237 | Delete Node in a Linked List | Solution | O(1) | O(1) | Easy | LinkedList | |
236 | Lowest Common Ancestor of a Binary Tree | Solution | O(n) | O(h) | Medium | DFS | |
235 | Lowest Common Ancestor of a Binary Search Tree | Solution | O(h) | O(1) | Easy | DFS | |
234 | Palindrome Linked List | Solution | O(n) | O(1) | Easy | Linked List | |
233 | Number of Digit One | Solution | O(n) | O(1) | Hard | Math | |
232 | Implement Queue using Stacks | Solution | O(n) | O(n) | Medium | Stack, Design | |
231 | Power of Two | Solution | O(1) | O(1) | Easy | ||
230 | Kth Smallest Element in a BST | Solution | O(n) | O(k) | Medium | Tree | |
229 | Majority Element II | Solution | O(n) | O(n) | Medium | ||
228 | Summary Ranges | Solution | O(n) | O(1) | Medium | Array | |
227 | Basic Calculator II | Solution | O(n) | O(n) | Medium | String | |
226 | Invert Binary Tree | Solution | O(n) | O(h) | Easy | DFS, recursion | |
225 | Implement Stack using Queues | Solution | O(n) | O(n) | Easy | Stack, Queue | |
224 | Basic Calculator | Solution | ? | ? | Hard | ||
223 | Rectangle Area | Solution | O(1) | O(1) | Easy | ||
222 | Count Complete Tree Nodes | Solution | O(?) | O(h) | Medium | Recursion | |
221 | Maximal Square | Solution | O(?) | O(h) | Medium | Recursion | |
220 | Contains Duplicate III | Solution | O(nlogn) | O(n) | Medium | TreeSet | |
219 | Contains Duplicate II | Solution | O(n) | O(n) | Easy | HashMap | |
218 | The Skyline Problem | Solution | O(n) | O(n) | Hard | TreeMap, Design | |
217 | Contains Duplicate | Solution | O(n) | O(n) | Easy | HashSet | |
216 | Combination Sum III | Solution | O(k * C(n, k)) | O(k) | Medium | Backtracking | |
215 | Kth Largest Element in an Array | Solution | O(nlogn) | O(n) | Medium | Heap | |
214 | Shortest Palindrome | Solution | O(?) | O(?) | Hard | KMP | |
213 | House Robber II | Solution | O(n) | O(n) | Medium | DP | |
212 | Word Search II | Solution | O(mnl) | O(l) | Hard | Trie | |
211 | Add and Search Word - Data structure design | Solution | O(n) | O(h) | Medium | Trie | |
210 | Course Schedule II | Solution | O(?) | O(?) | Medium | ||
209 | Minimum Size Subarray Sum | Solution | O(n) | O(1) | Medium | ||
208 | Implement Trie | Solution | O(n) | O(1) | Medium | Trie | |
207 | Course Schedule | Solution | O(?) | O(?) | Medium | ||
206 | Reverse Linked List | Solution | O(n) | O(1) | Easy | Linked List | |
205 | Isomorphic Strings | Solution | O(n) | O(1) | Easy | ||
204 | Count Primes | Solution | O(sqrt(n)) | O(n) | Easy | ||
203 | Remove Linked List Elements | Solution | O(n) | O(1) | Easy | ||
202 | Happy Number | Solution | O(k) | O(k) | Easy | ||
201 | Bitwise AND of Numbers Range | Solution | O(min(m,n)) | O(1) | Medium | Bit Manipulation | |
200 | Number of Islands | Solution | O(m*n) | O(m*n) | Medium | Union Find, DFS | |
199 | Binary Tree Right Side View | Solution | O(n) | O(h) | Medium | BFS | |
198 | House Robber | Solution | O(n) | O(n) | Easy | DP | |
191 | Number of 1 Bits | Solution | O(n) | O(1) | Easy | Bit Manipulation | |
190 | Reverse Bits | Solution | O(n) | O(1) | Easy | Bit Manipulation | |
189 | Rotate Array | Solution | O(n) | O(n), could be optimized to O(1) | Easy | ||
188 | Best Time to Buy and Sell Stock IV | Solution | O(n*k) | O(n*k) | Hard | DP | |
187 | Repeated DNA Sequences | Solution | O(n) | O(n) | Medium | ||
186 | Reverse Words in a String II | Solution | O(n) | O(1) | Medium | ||
179 | Largest Number | Solution | O(?) | O(?) | Medium | ||
174 | Dungeon Game | Queue Stack | O(m*n) | O(m*n) | Hard | DP | |
173 | Binary Search Tree Iterator | Queue Stack | O(1) | O(h) | Medium | Stack, Design | |
172 | Factorial Trailing Zeroes | Solution | O(logn) | O(1) | Easy | ||
171 | Excel Sheet Column Number | Solution | O(n) | O(1) | Easy | ||
170 | Two Sum III - Data structure design | Solution | O(n) | O(n) | Easy | ||
169 | Majority Element | Solution | O(n) | O(1) | Easy | ||
168 | Excel Sheet Column Title | Solution | O(n) | O(1) | Easy | ||
167 | Two Sum II - Input array is sorted | Solution | O(logn) | O(1) | Easy | ||
166 | Fraction to Recurring Decimal | Solution | O(1) | O(1) | Medium | HashMap | |
165 | Compare Version Numbers | Solution | O(n) | O(1) | Easy | ||
164 | Maximum Gap | Solution | O(n) | O(n) | Hard | ||
163 | Missing Ranges | Solution | O(n) | O(1) | |||
162 | Find Peak Element | Solution | O(1) | O(logn)/O(n) | Binary Search | ||
161 | One Edit Distance | Solution | O(n) | O(1) | |||
160 | Intersection of Two Linked Lists | Solution | O(m+n) | O(1) | Easy | Linked List | |
159 | Longest Substring with At Most Two Distinct Characters | Solution | O(n) | O(1) | Hard | String, Sliding Window | |
158 | Read N Characters Given Read4 II - Call multiple times | Solution | O(n) | O(1) | Hard | ||
157 | Read N Characters Given Read4 | Solution | O(n) | O(1) | Easy | ||
156 | Binary Tree Upside Down | Solution | O(n) | O(h) | Medium | Tree, Recursion | |
155 | Min Stack | Solution | O(1) | O(n) | Easy | Stack | |
154 | Find Minimum in Rotated Sorted Array II | Solution | O(logn) | O(1) | Hard | Array, Binary Search | |
153 | Find Minimum in Rotated Sorted Array | Solution | O(logn) | O(1) | Medium | Array, Binary Search | |
152 | Maximum Product Subarray | Solution | O(n) | O(1) | Medium | Array | |
151 | Reverse Words in a String | Solution | O(n) | O(n) | Medium | String | |
150 | Evaluate Reverse Polish Notation | Solution | O(?) | O(?) | Medium | ||
149 | Max Points on a Line | Solution | O(?) | O(?) | Hard | ||
148 | Sort List | Solution O(nlogn) | O(h) | Medium | Linked List, Sort | ||
147 | Insertion Sort List | Solution O(n^2) | O(1) | Medium | Linked List | ||
146 | LRU Cache | Solution | amortized O(1) | O(n) | Hard | Linked List | |
145 | Binary Tree Postorder Traversal | Solution | O(n) | O(h) | Hard | Binary Tree | |
144 | Binary Tree Preorder Traversal | Solution | O(n) | O(h) | Medium | Binary Tree | |
143 | Reorder List | Solution | O(n) | O(1) | Medium | ||
142 | Linked List Cycle II | Solution | O(n) | O(1) | Medium | Linked List | |
141 | Linked List Cycle | Solution | O(n) | O(1) | Easy | Linked List | |
140 | Word Break II | Solution | ? | O(n^2) | Hard | Backtracking/DFS | |
139 | Word Break | Solution | O(n^2) | O(n) | Medium | DP, Pruning | |
138 | Copy List with Random Pointer | Solution | O(n) | O(n) | Medium | LinkedList, HashMap | |
137 | Single Number II | Solution | O(n) | O(n) | Medium | ||
136 | Single Number | Solution | O(n) | O(n) | Medium | ||
135 | Candy | Solution | O(n) | O(1) | Hard | Greedy | |
134 | Gas Station | Solution | O(n) | O(1) | Medium | Greedy | |
133 | Clone Graph | Solution | O(n) | O(n) | Medium | HashMap, BFS, Graph | |
132 | Palindrome Partitioning II | Solution | O(n^2) | O(n^2) | Hard | ||
131 | Palindrome Partitioning | Solution | O(n^2) | O(n^2) | Medium | ||
130 | Surrounded Regions | Solution | O(?) | O(?) | Medium | ||
129 | Sum Root to Leaf Numbers | Solution | O(n) | O(h) | Medium | DFS | |
128 | Longest Consecutive Sequence | Solution | O(?) | O(?) | Hard | Union Find | |
127 | Word Ladder | Solution | O(n^2) | O(n) | Medium | BFS | |
126 | Word Ladder II | Solution | O(?) | O(?) | Hard | BFS | |
125 | Valid Palindrome | Solution | O(n) | O(1) | Easy | Two Pointers | |
124 | Binary Tree Maximum Path Sum | Solution | O(n) | O(h) | Hard | Tree, DFS | |
123 | Best Time to Buy and Sell Stock III | Solution | O(?) | O(?) | Hard | ||
122 | Best Time to Buy and Sell Stock II | Solution | O(n) | O(1) | Medium | Greedy | |
121 | Best Time to Buy and Sell Stock | Solution | O(n) | O(1) | Easy | DP | |
120 | Triangle | Solution | O(m*n) | O(n) | Medium | DP | |
119 | Pascal's Triangle II | Solution | O(n^2) | O(k) | Easy | ||
118 | Pascal's Triangle | Solution | O(n^2) | O(1) | Easy | ||
117 | Populating Next Right Pointers in Each Node II | Solution | O(n) | O(1) | Medium | BFS | |
116 | Populating Next Right Pointers in Each Node | Solution | O(n) | O(1) | Medium | BFS | |
115 | Distinct Subsequences | Solution | O(m*n) | O(m*n) | Hard | DP | |
114 | Flatten Binary Tree to Linked List | Solution | O(n) | O(h) | Medium | Tree | |
113 | Path Sum II | Solution | O(n) | O(h) | Medium | DFS | |
112 | Path Sum | Solution | O(n) | O(1) | Easy | DFS | |
111 | Minimum Depth of Binary Tree | Solution | O(n) | O(1)~O(h) | Easy | BFS, DFS | |
110 | Balanced Binary Tree | Solution | O(n) | O(1)~O(h) | Easy | DFS | |
109 | Convert Sorted List to Binary Search Tree | Solution | O(n) | O(h) | Medium | DFS, Recursion | |
108 | Convert Sorted Array to Binary Search Tree | Solution | O(n) | O(h) | Medium | Tree | |
107 | Binary Tree Level Order Traversal II | Solution | O(nlogn) | O(h) | Easy | BFS | |
106 | Construct Binary Tree from Inorder and Postorder Traversal | Solution | O(n) | O(n) | Medium | Recursion, Tree | |
105 | Construct Binary Tree from Preorder and Inorder Traversal | Solution | O(n) | O(n) | Medium | Recursion, Tree | |
104 | Maximum Depth of Binary Tree | Solution | O(n) | O(h) | Easy | DFS | |
103 | Binary Tree Zigzag Level Order Traversal | Solution | O(n) | O(h) | Medium | BFS,DFS | |
102 | Binary Tree Level Order Traversal | Solution | O(n) | O(h) | Medium | BFS | |
101 | Symmetric Tree | Solution | O(n) | O(h) | Easy | DFS | |
100 | Same Tree | Solution | O(n) | O(h) | Easy | DFS | |
99 | Recover Binary Search Tree | Solution | O(?) | O(?) | Hard | ||
98 | Validate Binary Search Tree | Solution | O(n) | O(h) | Medium | DFS/Recursion | |
97 | Interleaving String | Solution | O(?) | O(?) | Hard | DP | |
96 | Unique Binary Search Trees | Solution | O(n^2) | O(n) | Medium | Recursion, DP | |
95 | Unique Binary Search Trees II | Solution | O(?) | O(?) | Medium | Recursion | |
94 | Binary Tree Inorder Traversal | Solution | O(n) | O(h) | Medium | Binary Tree | |
93 | Restore IP Addresses | Solution | O(1) | O(1) | Medium | Backtracking | |
92 | Reverse Linked List II | Solution | O(n) | O(1) | Medium | ||
91 | Decode Ways | Solution | O(n) | O(n) | Medium | DP | |
90 | Subsets II | Solution | O(n^2) | O(1) | Medium | Backtracking | |
89 | Gray Code | Solution | O(n) | O(1) | Medium | Bit Manipulation | |
88 | Merge Sorted Array | Solution | O(max(m,n)) | O(1) | Easy | ||
87 | Scramble String | Solution | O(?) | O(?) | Hard | Recursion | |
86 | Partition List | Solution | O(n) | O(1) | Medium | ||
85 | Maximal Rectangle | Solution | O(m*n) | O(n) | Hard | DP | |
84 | Largest Rectangle in Histogram | Solution | O(n) | O(n) | Hard | Array, Stack | |
83 | Remove Duplicates from Sorted List | Solution | O(n) | O(1) | Medium | Linked List | |
82 | Remove Duplicates from Sorted List II | Solution | O(n) | O(1) | Medium | Linked List | |
81 | Search in Rotated Sorted Array II | Solution | O(logn) | O(1) | Medium | Binary Search | |
80 | Remove Duplicates from Sorted Array II | Solution | O(n) | O(n) | Medium | ||
79 | Word Search | Solution | O(mnl) ? | O(m*n) | Medium | Backtracking, DFS | |
78 | Subsets | Solution | O(n^2) | O(1) | Medium | Backtracking | |
77 | Combinations | Solution | O(n^2) ? | O(1) | Medium | Backtracking | |
76 | Minimum Window Substring | Solution | O(n) | O(k) | Hard | Two Pointers | |
75 | Sort Colors | Solution | O(n) | O(1) | Medium | Two Pointers | |
74 | Search a 2D Matrix | Solution | O(log(m*n)) | O(1) | Medium | Binary Search | |
73 | Set Matrix Zeroes | Solution | O(mn) | O(mn) | Medium | ||
72 | Edit Distance | Solution | O(m*n) | O(m+n) | Hard | ||
71 | Simplify Path | Solution | O(n) | O(n) | Medium | Stack | |
70 | Climbing Stairs | Solution | O(n) | O(n) | Easy | DP | |
69 | Sqrt(x) | Solution | O(logn) | O(1) | Easy | ||
68 | Text Justification | Solution | O(n) | O(1) | Hard | ||
67 | Add Binary | Solution | O(n) | O(1) | Easy | ||
66 | Plus One | Solution | O(n) | O(1) | Easy | ||
65 | Valid Number | Solution | O(n) | O(1) | Hard | ||
64 | Minimum Path Sum | Solution | O(m*n) | O(m*n) | Medium | DP | |
63 | Unique Paths II | Solution | O(m*n) | O(m*n) | Medium | DP | |
62 | Unique Paths | Solution | O(m*n) | O(m*n) | Medium | DP | |
61 | Rotate List | Solution | O(n) | O(1) | Medium | Linked List | |
60 | Permutation Sequence | Solution | ? | ? | Medium | ||
59 | Spiral Matrix II | Solution | O(n) | O(n) | Medium | ||
58 | Length of Last Word | Solution | O(n) | O(1) | Easy | ||
57 | Insert Intervals | Solution | O(n) | O(1) | Hard | Array, Sort | |
56 | Merge Intervals | Solution | O(n*logn) | O(1) | Medium | Array, Sort | |
55 | Jump Game | Solution | O(n) | O(1) | Medium | Greedy | |
54 | Spiral Matrix | Solution | O(m*n) | O(m*n) | Medium | Array | |
53 | Maximum Subarray | Solution | O(n) | O(1) | Easy | ||
52 | N-Queens II | Solution | O(?) | O(?) | Hard | ||
51 | N-Queens | Solution | O(?) | O(?) | Hard | ||
50 | Pow(x, n) | Solution | O(logn) | O(logn) | Medium | ||
49 | Group Anagrams | Solution | O(m*logn) | O(m*n) | Medium | HashMap | |
48 | Rotate Image | Solution | O(n^2) | O(1) | Medium | Array | |
47 | Permutations II | Solution | O(n*n!) | O(n) | Medium | Backtracking | |
46 | Permutations | Solution | O(n*n!) | O(n) | Medium | Backtracking | |
45 | Jump Game II | Solution | O(?) | O(?) | Hard | ||
44 | Wildcard Matching | Solution | O(m*n) | O(m*n) | Hard | Backtracking, DP, Greedy, String | |
43 | Multiply Strings | Solution | O(n) | O(1) | Medium | Array, String | |
42 | Trapping Rain Water | Solution | O(n) | O(1) | Hard | ||
41 | First Missing Positive | Solution | O(n) | O(1) | Hard | ||
40 | Combination Sum II | Solution | O(k*n^k) | O(k) | Medium | Backtracking | |
39 | Combination Sum | Solution | O(k*n^k) | O(k) | Medium | Backtracking | |
38 | Count and Say | Solution | O(n*2^n) | O(2^n) | Easy | Recursion, LinkedList | |
37 | Sudoku Solver | Solution | O((9!)^9) | O(1) | Hard | ||
36 | Valid Sudoku | Solution | O(1) | O(1) | Medium | ||
35 | Search Insert Position | Solution | O(n) | O(1) | Easy | Array | |
34 | Search for a Range | Solution | O(logn) | O(1) | Medium | Array, Binary Search | |
33 | Search in Rotated Sorted Array | Solution | O(logn) | O(1) | Medium | Binary Search | |
32 | Longest Valid Parentheses | Solution | O(n) | O(n) | Hard | Stack, DP | |
31 | Next Permutation | Solution | O(n) | O(1) | Medium | Array | |
30 | Substring with Concatenation of All Words | Solution | O(n^2) | O(n) | Hard | HashMap | |
29 | Divide Two Integers | Solution | O(?) | O(?) | Medium | ||
28 | Implement strStr() | Solution | O(n) | O(1) | Easy | String | |
27 | Remove Element | Solution | O(n) | O(1) | Easy | ||
26 | Remove Duplicates from Sorted Array | Solution | O(n) | O(1) | Easy | Array | |
25 | Reverse Nodes in k-Group | Solution | O(n) | O(1) | Hard | Recursion, LinkedList | |
24 | Swap Nodes in Pairs | Solution | O(n) | O(h) | Medium | Recursion, LinkedList | |
23 | Merge k Sorted Lists | Solution | O(n*logk) | O(k) | Hard | Heap | |
22 | Generate Parentheses | Solution | TBD | O(n) | Medium | Backtracking | |
21 | Merge Two Sorted Lists | Solution | O(n) | O(h) | Easy | Recursion | |
20 | Valid Parentheses | Solution | O(n) | O(n) | Easy | Stack | |
19 | Remove Nth Node From End of List | Solution | O(n) | O(1) | Medium | Linked List | |
18 | 4 Sum | Solution | O(n^2) | O(1) | Medium | Two Pointers | |
17 | Letter Combinations of a Phone Number | Solution | O(n*4^n) | O(n) | Medium | Backtracking | |
16 | 3Sum Closest | Solution | O(nlogn) | O(1) | Medium | Two Pointers | |
15 | 3Sum | Solution | O(n^2) | O(1) | Medium | Two Pointers, Binary Search | |
14 | Longest Common Prefix | Solution | O(n*min(wordLength in this array)) | O(1) | Easy | ||
13 | Roman to Integer | Solution | O(1) | O(1) | Easy | ||
12 | Integer to Roman | Solution | O(1) | O(1) | Medium | ||
11 | Container With Most Water | Solution | O(n) | O(1) | Medium | ||
10 | Regular Expression Matching | Solution | O(m*n) | O(m*n) | Hard | DP | |
9 | Palindrome Number | Solution | O(logn)/(n) | O(1) | Easy | ||
8 | String to Integer (atoi) | Solution | O(n) | O(1) | Medium | ||
7 | Reverse Integer | Solution | O(1) | O(1) | Easy | ||
6 | ZigZag Conversion | Solution | O(n) | O(n) | Easy | ||
5 | Longest Palindromic Substring | Solution | O(n^2) | O(1) | Medium | ||
4 | Median of Two Sorted Arrays | Solution | ? | ? | Hard | Divide and Conquer | |
3 | Longest Substring Without Repeating Characters | Solution | O(n) | O(k) | Medium | HashMap, Sliding Window | |
2 | Add Two Numbers | Solution | O(max(m,n)) | O(1) | Medium | LinkedList | |
1 | Two Sum | Solution | O(n) | O(n) | Easy | HashMap |
# | Title | Solutions | Time | Space | Difficulty | Tag | Notes |
---|---|---|---|---|---|---|---|
195 | Tenth Line | Solution | O(n) | O(1) | Easy | ||
194 | Transpose File | Solution | O(n^2) | O(n^2) | Medium | ||
193 | Valid Phone Numbers | Solution | O(n) | O(1) | Easy | ||
192 | Word Frequency | Solution | O(n) | O(k) | Medium |