/Leetcode

Complete solutions to Leetcode problems; updated daily.

Primary LanguageJavaApache License 2.0Apache-2.0

If you like this project, please leave me a star.

"For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."

##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.

Contributing

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!

Algorithms

# Title Solutions Time Space Video Difficulty Tag
844 Backspace String Compare Solution O(n) O(1) Easy
832 Flipping an Image Solution O(n) O(1) Easy
830 Positions of Large Groups Solution O(n) O(n) Easy
824 Goat Latin Solution O(n) O(1) Easy
821 Shortest Distance to a Character Solution O(n) O(k) (k is the number of char C in S) Easy
819 Most Common Word Solution O(m+n) O(n) Easy HashMap
811 Subdomain Visit Count Solution O(n) O(n) Easy HashMap
806 Number of Lines To Write String Solution O(n) O(1) Easy
804 Unique Morse Code Words Solution O(S) O(S) Easy
800 Similar RGB Color Solution O(1) O(1) Easy
799 Champagne Tower Solution O(r^2) or O(1) O(r^2) or O(1) Medium
796 Rotate String Solution O(n) O(1) Easy
791 Custom Sort String Solution O(n+m) O(1) Medium
788 Rotated Digits Solution O(n*m) O(1) Easy
784 Letter Case Permutation Solution O(n*2^n) O(n*2^n) Easy
783 Minimum Distance Between BST Nodes Solution O(n) O(h) Easy
779 K-th Symbol in Grammar Solution O(logn) O(1) Medium
776 Split BST Solution O(n) O(n) Medium Recursion
771 Jewels and Stones Solution O(n) O(m) Easy
769 Max Chunks To Make Sorted Solution O(n) O(1) Medium Array
767 Reorganize String Solution O(klogk) k is the number of unique characters in given String O(k) Medium
766 Toeplitz Matrix Solution O(m*n) O(1) Easy
765 Couples Holding Hands Solution O(n^2) O(1) Hard
764 Largest Plus Sign Solution O(n^2) O(n^2) Medium DP
763 Partition Labels Solution O(n) O(1) Medium
762 Prime Number of Set Bits in Binary Representation Solution O(n) O(1) Easy
760 Find Anagram Mappings Solution O(n^2) O(1) Easy
758 Bold Words in String Solution O(n*k) O(n Easy
756 Pyramid Transition Matrix Solution O(?) O(?) Medium Backtracking
755 Pour Water Solution O(V*N) O(1) Medium Array
754 Reach a Number Solution O(n) O(1) Medium Math
750 Number Of Corner Rectangles Solution O((m*n)^2) O(1) Medium
748 Shortest Completing Word Solution O(n) O(1) Easy
747 Largest Number Greater Than Twice of Others Solution O(n) O(1) Easy
746 Min Cost Climbing Stairs Solution O(n) O(1) Easy
744 Find Smallest Letter Greater Than Target Solution O(logn) O(1) Easy
740 Delete and Earn Solution O(n) O(n) Medium
739 Daily Temperatures Solution O(n^2) O(1) Medium
738 Monotone Increasing Digits Solution O(n) O(1) Medium
737 Sentence Similarity II Solution O(nlogk + k) n is the length of max(words1, words2), k is the length of pairs O(k) Medium Union Find
735 Asteroid Collision Solution O(n) O(n) Medium Stack
734 Sentence Similarity Solution O(n*k) O(1) Easy HashTable
733 Flood Fill Solution O(m*n) O(m*n) Easy BFS, DFS
729 My Calendar I Solution O(n) O(n) Medium
728 Self Dividing Numbers Solution O(n*k) k is the average number of digits of each number in the given array O(1) Easy
727 Minimum Window Subsequence Solution O(m*n) O(m*n) Hard DP
725 Split Linked List in Parts Solution O(n+k) O(k) Medium LinkedList
724 Find Pivot Index Solution O(n) O(1) Easy Array
723 Candy Crush Solution O((r*c)^2) O((r*c)) Medium Array, Two Pointers
721 Accounts Merge Solution Medium DFS, Union Find
720 Longest Word in Dictionary Solution O(∑wi) where wi is the length of words[i] O(∑wi) where wi is the length of words[i] Easy Trie
719 Find K-th Smallest Pair Distance Solution O(nlogw + nlogn) O(1) Hard Binary Search
718 Maximum Length of Repeated Subarray Solution O(m*n) O(m*n) Medium DP
717 1-bit and 2-bit Characters Solution O(n) O(1) Easy
716 Max Stack Solution O(logn) O(n) Hard Design
714 Best Time to Buy and Sell Stock with Transaction Fee Solution O(n) O(1) Medium DP
713 Subarray Product Less Than K Solution O(n) O(1) Medium
712 Minimum ASCII Delete Sum for Two Strings Solution O(m*n) O(m*n) Medium DP
699 Falling Squares Solution O(n^2) O(n) Hard Segment Tree
698 Partition to K Equal Sum Subsets Solution O(n*(2^n)) O(2^n) Medium Backtracking
697 Degree of an Array Solution O(n) O(n) Easy
696 Count Binary Substrings Solution O(n) O(n) Easy
695 Max Area of Island Solution O(m*n) O(1) Easy DFS
694 Number of Distinct Islands Solution O(m*n) O(1) Medium DFS
693 Binary Number with Alternating Bits Solution O(n) O(1) Easy
692 Top K Frequent Words Solution O(nlogk) O(n) Medium
691 Stickers to Spell Word Solution O(?) O(?) Hard DP
690 Employee Importance Solution O(n) O(h) Easy DFS
689 Maximum Sum of 3 Non-Overlapping Subarrays Solution O(n) O(n) Hard DP
688 Knight Probability in Chessboard Solution O(n^2) O(n^2) Medium DP
687 Longest Univalue Path Solution O(n) O(h) Easy DFS
686 Repeated String Match Solution O(n*(m+n)) O(m+n) Easy
685 Redundant Connection II Solution O(n) O(n) Hard Union Find
684 Redundant Connection Solution O(n) O(n) Medium Union Find
683 K Empty Slots Solution O(n) O(n) Hard
682 Baseball Game Solution O(n) O(1) Easy
681 Next Closest Time Solution O(1) O(1) Medium
680 Valid Palindrome II Solution O(n) O(1) Easy String
679 24 Game Solution O(1) (Upper bound 9216) O(1) Hard Recursion
678 Valid Parenthesis String Solution O(n) O(1) Medium Recursion, Greedy
677 Map Sum Pairs Solution O(n) O(n) Medium HashMap
676 Implement Magic Dictionary Solution O(n^2) O(n) Medium
675 Cut Off Trees for Golf Event Solution O((m*n)^2) O(m*n) Hard BFS
674 Longest Continuous Increasing Subsequence Solution O(n^2) O(1) Easy
673 Number of Longest Increasing Subsequence Solution O(n^2) O(n) Medium DP
672 Bulb Switcher II Solution O(1) O(1) Medium Math
671 Second Minimum Node In a Binary Tree Solution O(n) O(n) Easy Tree, DFS
670 Maximum Swap Solution O(n^2) O(1) Medium String
669 Trim a Binary Search Tree Solution O(n) O(1) Easy Tree, DFS
668 Kth Smallest Number in Multiplication Table Solution O(logm*n) O(1) Hard Binary Search
667 Beautiful Arrangement II Solution O(n) O(1) Medium Array
666 Path Sum IV Solution O(1) O(1) Medium Tree, DFS
665 Non-decreasing Array Solution O(n) O(n) Easy
664 Strange Printer Solution O(n^3) O(n^2) Hard DP
663 Equal Tree Partition Solution O(n) O(n) Medium Tree
662 Maximum Width of Binary Tree Solution O(n) O(k) Medium BFS, DFS
661 Image Smoother Solution O(m*n) O(1) Easy Array
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) 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, Greedy
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(n) 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(x) (x 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(l1 + 26*(l2 - l1)) 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(n) 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(logn) O(1) Medium String
538 Convert BST to Greater Tree Solution O(n) O(h) Easy 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(nlogn) O(1) Hard Recursion
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 String, KMP
458 Poor Pigs Solution O(1) O(1) Easy Math
457 Circular Array Loop Solution O(n) O(1) Medium
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
443 String Compression Solution O(n) O(n) Easy
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
395 Longest Substring with At Least K Repeating Characters Solution O(n^2) O(1) Medium Recursion
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) Easy String
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
378 Kth Smallest Element in a Sorted Matrix Solution O(logm*n) O(1) Medium Binary Search
377 Combination Sum IV Solution O(n^2) O(n) Medium DP
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(klogk) O(k) 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 Array
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(k) k is is the number of unique elements in the given array Medium HashTable, Heap, Bucket Sort
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) 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(m*n) O(m*n) Hard DFS, DP
328 Odd Even Linked List Solution O(n) O(1) Medium Linked List
327 Count of Range Sum Solution O(nlogn) O(n) Hard BST, Divide and Conquer
326 Power of Three Solution O(1) O(1) Easy Math
325 Maximum Size Subarray Sum Equals k Solution O(n) O(n) Medium HashTable
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(n*k) O(k) Medium DP
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(logn) 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 Recursion, Backtracking
290 Word Pattern Solution O(n) O(n) Easy HashMap
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(1) O(k) 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 O(n*k) O(1) Hard DP
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(1) 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(nloglogn) O(n) Easy The Sieve of Eratosthenes
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(1) 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 Solution 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(n) O(1) Easy Binary Search
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(k) Hard Doubly Linked List, LinkedHashMap
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(1) Medium Bit Manipulation
136 Single Number Solution O(n) O(1) Easy Bit Manipulation
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(n) O(n) 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(n) O(1) Hard DP
122 Best Time to Buy and Sell Stock II Solution O(n) O(1) Easy Greedy
121 Best Time to Buy and Sell Stock Solution O(n) O(1) Easy
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, Backtracking
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) Easy 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(?) O(?) 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(n^4) O(n^3 Hard Recursion
86 Partition List Solution O(n) O(1) Medium Linked List
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) Easy 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((m*n)^2) O(m*n) Medium Backtracking, DFS
78 Subsets Solution O(n^2) O(1) Medium Backtracking
77 Combinations Solution O(n!) O(n) 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(1) 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 O(n^2) O(n) Medium Math, Backtracking
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 Array
52 N-Queens II Solution O(n!) O(n) Hard Backtracking
51 N-Queens Solution O(n!) O(n) Hard
50 Pow(x, n) Solution O(logn) O(logn) Medium
49 Group Anagrams Solution O(m*klogk) O(m*k) 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(n) O(1) Hard Array, Greedy
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 Array
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(S) (S is the sum of all characters in all strings) O(1) Easy
13 Roman to Integer Solution O(1) O(1) Easy Math, String
12 Integer to Roman Solution O(1) O(1) Medium Math, String
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(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

Database

# Title Solutions Time Space Difficulty Tag
627 Swap Salary Solution Easy
626 Exchange Seats Solution Medium
620 Not Boring Movies Solution Easy
619 Biggest Single Number Solution Easy
618 Students Report By Geography Solution Hard Session Variables
615 Average Salary: Departments VS Company Solution Hard
614 Second Degree Follower Solution Medium Inner Join
613 Shortest Distance in a Line Solution Easy
612 Shortest Distance in a Plane Solution Medium
610 Triangle Judgement Solution Easy
608 Tree Node Solution Medium Union
607 Sales Person Solution Easy
603 Consecutive Available Seats Solution Easy
602 Friend Requests II: Who Has the Most Friends Solution Medium
601 Human Traffic of Stadium Solution Hard
597 Friend Requests I: Overall Acceptance Rate Solution Easy
596 Classes More Than 5 Students Solution Easy
595 Big Countries Solution O(n) O(1) Easy
586 Customer Placing the Largest Number of Orders Solution Easy
585 Investments in 2016 Solution Medium
584 Find Customer Referee Solution Easy
580 Count Student Number in Departments Solution Medium Left Join
578 Get Highest Answer Rate Question Solution Medium
577 Employee Bonus Solution Easy
574 Winning Candidate Solution Medium
571 Find Median Given Frequency of Numbers Solution Hard
570 Managers with at Least 5 Direct Reports Solution Medium
569 Median Employee Salary Solution Hard
262 Trips and Users Solution Hard Inner Join
197 Rising Temperature Solution O(n^2) O(n) Easy
196 Delete Duplicate Emails Solution O(n^2) O(n) Easy
185 Department Top Three Salaries Solution Hard
184 Department Highest Salary Solution O(n^2) O(n) Medium
183 Customers Who Never Order Solution O(n^2) O(n) Easy
182 Duplicate Emails Solution O(n^2) O(n) Easy
181 Employees Earning More Than Their Managers Solution O(n^2) O(n) Easy
180 Consecutive Numbers Solution O(n) O(n) Medium
178 Rank Scores Solution ? ? Medium
177 Nth Highest Salary Solution O(n) O(1) Medium
176 Second Highest Salary Solution O(n) O(1) Easy
175 Combine Two Tables Solution O(m+n) O(m+n) Easy

Shell

# Title Solutions Time Space Difficulty Tag
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