zfu1316 / LeetCode

Solutions of LeetCode problems

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LeetCode Summary

Solutions and thoughts about LeetCode problems.

Data Structrue

Array

  1. Design Circular Deque
  2. Set Mismatch
  3. Pairs of Songs With Total Durations Divisible by 60
  4. Sum of Digits in the Minimum Number

Linked List

  1. Plus One Linked List
  2. Insert into a Sorted Circular Linked List
  3. Max Stack
  4. Split Linked List in Parts
  5. Middle of the Linked List
  6. Convert Binary Number in a Linked List to Integer

Hash Table

  1. Isomorphic Strings
  2. Unique Word Abbreviation
  3. Word Pattern
  4. Maximum Size Subarray Sum Equals k
  5. Design Snake Game
  6. Line Reflection
  7. Find Duplicate Subtrees
  8. Accounts Merge
  9. Subdomain Visit Count
  10. Maximum Frequency Stack
  11. Minimum Area Rectangle
  12. N-Repeated Element in Size 2N Array
  13. Subarray Sums Divisible by K
  14. Cousins in Binary Tree
  15. Find Common Characters
  16. Pairs of Songs With Total Durations Divisible by 60
  17. Longest Arithmetic Sequence
  18. Longest String Chain
  19. Unique Number of Occurrences
  20. Intersection of Three Sorted Arrays
  21. Longest Arithmetic Subsequence of Given Difference
  22. Design A Leaderboard
  23. Find Elements in a Contaminated Binary Tree
  24. Count Servers that Communicate
  25. Group the People Given the Group Size They Belong To
  26. Element Appearing More Than 25% In Sorted Array
  27. Get Watched Videos by Your Friends

Stack

  1. Validate Binary Search Tree
  2. Basic Calculator
  3. Basic Calculator II
  4. Inorder Successor in BST (inorder traversal)
  5. Decode String
  6. Convert Binary Search Tree to Sorted Doubly Linked List (inorder traversal)
  7. Tag Validator
  8. Baseball Game
  9. Search in a Binary Search Tree
  10. Asteroid Collision
  11. Basic Calculator III
  12. Minimum Distance Between BST Nodes
  13. Maximum Frequency Stack
  14. Remove All Adjacent Duplicates In String
  15. Remove All Adjacent Duplicates in String II

Queue

  1. Binary Tree Zigzag Level Order Traversal
  2. Zigzag Iterator
  3. Walls and Gates
  4. Design Snake Game
  5. Design Hit Counter
  6. Average of Levels in Binary Tree
  7. Closest Leaf in a Binary Tree
  8. Open the Lock
  9. Sliding Puzzle
  10. Shortest Distance to a Character
  11. Duplicate Zeros
  12. Shortest Path in Binary Matrix
  13. Web Crawler
  14. Tree Diameter
  15. Shortest Path in a Grid with Obstacles Elimination
  16. Deepest Leaves Sum
  17. Get Watched Videos by Your Friends

Heap

  1. The Skyline Problem
  2. Meeting Rooms II
  3. Course Schedule III (maxHeap)
  4. Design Search Autocomplete System
  5. Network Delay Time (shortest path)
  6. Reorganize String
  7. Exam Room
  8. Last Stone Weight (maxHeap)
  9. Campus Bikes (minHeap)
  10. Path With Maximum Minimum Value (maxHeap)
  11. Optimize Water Distribution in a Village (MST)
  12. Search Suggestions System
  13. Minimum Falling Path Sum II (minHeap)
  14. Get Watched Videos by Your Friends

Monotonic Queue

  1. Largest Rectangle in Histogram
  2. Sliding Window Maximum
  3. Daily Temperatures
  4. Shortest Subarray with Sum at Least K (Deque)
  5. Online Stock Span
  6. Sum of Subarray Minimums

Tree

  1. Validate Binary Search Tree (BST)
  2. Binary Tree Zigzag Level Order Traversal
  3. Inorder Successor in BST (BST)
  4. Binary Tree Vertical Order Traversal (BST)
  5. Largest BST Subtree (BST)
  6. Convert Binary Search Tree to Sorted Doubly Linked List (BST)
  7. Construct String from Binary Tree
  8. Average of Levels in Binary Tree
  9. Find Duplicate Subtrees
  10. Print Binary Tree
  11. Trim a Binary Search Tree (BST)
  12. Longest Univalue Path
  13. Search in a Binary Search Tree (BST)
  14. Max Stack (TreeMap)
  15. Closest Leaf in a Binary Tree
  16. Minimum Distance Between BST Nodes (BST)
  17. Binary Tree Pruning
  18. Cousins in Binary Tree
  19. Delete Nodes And Return Forest
  20. Design A Leaderboard
  21. Tree Diameter
  22. Find Elements in a Contaminated Binary Tree
  23. Delete Tree Nodes
  24. All Elements in Two Binary Search Trees (BST)
  25. Sum of Nodes with Even-Valued Grandparent

Graph

  1. Alien Dictionary
  2. Find the Celebrity
  3. Closest Leaf in a Binary Tree
  4. Network Delay Time (shortest path)
  5. Is Graph Bipartite?
  6. Cheapest Flights Within K Stops
  7. Optimize Water Distribution in a Village (MST)
  8. Tree Diameter
  9. Get Watched Videos by Your Friends

Union Find

  1. Number of Islands II
  2. Number of Connected Components in an Undirected Graph (模版题)
  3. Friend Circles
  4. Redundant Connection II
  5. Accounts Merge
  6. Path With Maximum Minimum Value
  7. Number of Operations to Make Network Connected

Trie

  1. Word Search II
  2. Design Search Autocomplete System
  3. Search Suggestions System

String

  1. Longest Substring with At Most Two Distinct Characters
  2. Largest Number
  3. Encode and Decode Strings
  4. Unique Word Abbreviation
  5. Word Pattern
  6. Word Pattern II
  7. Longest Substring with At Most K Distinct Characters
  8. Robot Return to Origin
  9. Next Closest Time
  10. Rotate String
  11. Goat Latin
  12. Buddy Strings
  13. Find Common Characters
  14. Shortest Way to Form String
  15. Index Pairs of a String
  16. Defanging an IP Address
  17. Remove Sub-Folders from the Filesystem
  18. Web Crawler
  19. Hexspeak
  20. Decrypt String from Alphabet to Integer Mapping
  21. Minimum Insertion Steps to Make a String Palindrome

Algorithm

Sort

  1. Largest Number
  2. Meeting Rooms
  3. Meeting Rooms II
  4. Wiggle Sort
  5. Find the Duplicate Number
  6. Maximum Product of Three Numbers
  7. Sort an Array
  8. Minimum Increment to Make Array Unique
  9. Pancake Sorting
  10. Campus Bikes (Bucket Sort)
  11. Index Pairs of a String
  12. High Five
  13. Two Sum Less Than K
  14. Maximum Profit in Job Scheduling
  15. Remove Covered Intervals

Two Pointers

  1. Find the Duplicate Number (fast & slow)
  2. Plus One Linked List
  3. Insert into a Sorted Circular Linked List (prev & curr)
  4. Unique Letter String
  5. Middle of the Linked List (fast & slow)
  6. Sort Array By Parity (low & high)
  7. Two Sum Less Than K (low & high)
  8. Remove All Adjacent Duplicates in String II (left & right)
  9. Intersection of Three Sorted Arrays

Binary Search

  1. Kth Smallest Element in a Sorted Matrix (search in range)
  2. Random Pick with Weight
  3. Valid Triangle Number
  4. Search in a Sorted Array of Unknown Size
  5. Maximum Length of Repeated Subarray (search in index or length)
  6. My Calendar I
  7. My Calendar II
  8. Koko Eating Bananas (search in range)
  9. Shortest Way to Form String
  10. Missing Element in Sorted Array (in index)
  11. Check If a Number Is Majority Element in a Sorted Array
  12. Online Majority Element In Subarray
  13. Intersection of Three Sorted Arrays
  14. Missing Number In Arithmetic Progression (search in index)
  15. Maximum Profit in Job Scheduling (search in index)
  16. Find Positive Integer Solution for a Given Equation
  17. Element Appearing More Than 25% In Sorted Array (search in index)
  18. Maximum Side Length of a Square with Sum Less than or Equal to Threshold (search in length)
  19. Sum of Mutated Array Closest to Target (search in range)

Recursion (DFS)

  1. Validate Binary Search Tree
  2. Course Schedule
  3. Course Schedule II
  4. Word Search II
  5. Walls and Gates
  6. Largest BST Subtree
  7. Nested List Weight Sum
  8. Nested List Weight Sum II
  9. Find Leaves of Binary Tree (post order traversal)
  10. Plus One Linked List
  11. Convert Binary Search Tree to Sorted Doubly Linked List (inorder traversal)
  12. Robot Room Cleaner
  13. The Maze
  14. Construct String from Binary Tree
  15. Find Duplicate Subtrees
  16. Print Binary Tree
  17. Trim a Binary Search Tree
  18. Longest Univalue Path (postorder traversal)
  19. Employee Importance
  20. Number of Distinct Islands
  21. Max Area of Island
  22. Search in a Binary Search Tree (preorder traversal)
  23. Candy Crush
  24. Minimum Distance Between BST Nodes (inorder traversal)
  25. Is Graph Bipartite?
  26. Binary Tree Pruning
  27. Leaf-Similar Trees
  28. Cousins in Binary Tree
  29. Sum of Root To Leaf Binary Numbers
  30. Delete Nodes And Return Forest
  31. Two Sum BSTs (preorder traversal)
  32. Queens That Can Attack the King
  33. Tree Diameter
  34. Number of Closed Islands
  35. Find Elements in a Contaminated Binary Tree
  36. Delete Tree Nodes
  37. All Elements in Two Binary Search Trees (inorder traversal)
  38. Sum of Nodes with Even-Valued Grandparent

Backtracking (DFS)

  1. Generate Parentheses
  2. Word Ladder II
  3. Factor Combinations
  4. Word Pattern II
  5. Design Search Autocomplete System
  6. All Paths From Source to Target
  7. Unique Paths III
  8. Campus Bikes II
  9. Brace Expansion
  10. Stepping Numbers
  11. Path with Maximum Gold
  12. Maximum Score Words Formed by Letters
  13. Iterator for Combination

Recursion with Memoization (Top-down)

  1. Word Break
  2. Word Break II
  3. All Paths From Source to Target
  4. Campus Bikes II
  5. Count Vowels Permutation
  6. Dice Roll Simulation
  7. Jump Game III
  8. Minimum Insertion Steps to Make a String Palindrome

Dynamic Programming (Bottom-up)

  1. Word Break
  2. House Robber
  3. Bomb Enemy
  4. Sentence Screen Fitting
  5. Valid Parenthesis String
  6. Best Time to Buy and Sell Stock with Transaction Fee
  7. Maximum Length of Repeated Subarray
  8. Delete and Earn
  9. Minimum Falling Path Sum
  10. Minimum Cost For Tickets
  11. Best Sightseeing Pair
  12. Longest Arithmetic Sequence
  13. Maximum Sum of Two Non-Overlapping Subarrays
  14. Longest String Chain
  15. Longest Arithmetic Subsequence of Given Difference
  16. Dice Roll Simulation
  17. Maximum Profit in Job Scheduling
  18. Maximum Score Words Formed by Letters
  19. Greatest Sum Divisible by Three
  20. Minimum Falling Path Sum II

BFS

  1. Binary Tree Zigzag Level Order Traversal
  2. Word Ladder II
  3. Word Ladder
  4. Course Schedule
  5. Course Schedule II
  6. Walls and Gates
  7. Binary Tree Vertical Order Traversal
  8. Nested List Weight Sum
  9. Nested List Weight Sum II
  10. The Maze
  11. The Maze II
  12. Average of Levels in Binary Tree
  13. Employee Importance
  14. Closest Leaf in a Binary Tree
  15. Network Delay Time (shortest path)
  16. Open the Lock
  17. Sliding Puzzle
  18. Is Graph Bipartite?
  19. All Paths From Source to Target
  20. Shortest Distance to a Character
  21. Snakes and Ladders
  22. Shortest Path in Binary Matrix
  23. Path With Maximum Minimum Value
  24. Web Crawler
  25. Tree Diameter
  26. Minimum Moves to Move a Box to Their Target Location
  27. Sequential Digits
  28. Shortest Path in a Grid with Obstacles Elimination
  29. Deepest Leaves Sum
  30. Jump Game III
  31. Get Watched Videos by Your Friends

Quick Select

  1. Kth Largest Element in an Array

Morris Traversal

  1. Validate Binary Search Tree
  2. Inorder Successor in BST
  3. Search in a Binary Search Tree
  4. Minimum Distance Between BST Nodes

Sliding Window

  1. Minimum Window Substring (模版题)
  2. Longest Substring with At Most Two Distinct Characters
  3. Sliding Window Maximum
  4. Longest Substring with At Most K Distinct Characters
  5. Replace the Substring for Balanced String

Greedy

  1. Text Justification
  2. Find the Celebrity
  3. Wiggle Sort
  4. Non-overlapping Intervals
  5. Minimum Number of Arrows to Burst Balloons
  6. Can Place Flowers
  7. Course Schedule III
  8. Valid Parenthesis String
  9. Reorganize String
  10. Shortest Distance to a Character
  11. Broken Calculator
  12. Minimum Domino Rotations For Equal Row
  13. Shortest Way to Form String
  14. Play with Chips
  15. Split a String in Balanced Strings
  16. Reconstruct a 2-Row Binary Matrix
  17. Group the People Given the Group Size They Belong To

Divide & Conquer

  1. Count of Smaller Numbers After Self
  2. Count of Range Sum

Dijkstra's Algorithm (minHeap)

  1. Network Delay Time
  2. Cheapest Flights Within K Stops

Topological Sort (DFS, BFS)

  1. Alien Dictionary
  2. Course Schedule
  3. Course Schedule II

Sweep Line

  1. The Skyline Problem
  2. Meeting Rooms II
  3. Range Addition

Bit Manipulation

  1. Game of Life
  2. Image Smoother
  3. Prime Number of Set Bits in Binary Representation
  4. Campus Bikes II
  5. Adding Two Negabinary Numbers
  6. Maximum Score Words Formed by Letters
  7. XOR Queries of a Subarray
  8. Minimum Flips to Make a OR b Equal to c

Math

  1. Basic Calculator II
  2. Sparse Matrix Multiplication
  3. Line Reflection
  4. Plus One Linked List
  5. Elimination Game
  6. Maximum Product of Three Numbers
  7. Basic Calculator III
  8. Reaching Points
  9. Rectangle Overlap
  10. Transpose Matrix
  11. Minimum Increment to Make Array Unique
  12. Subarray Sums Divisible by K
  13. Broken Calculator
  14. Robot Bounded In Circle
  15. Confusing Number
  16. Adding Two Negabinary Numbers
  17. Sum of Digits in the Minimum Number
  18. Check If a Number Is Majority Element in a Sorted Array
  19. Play with Chips
  20. Check If It Is a Straight Line
  21. Greatest Sum Divisible by Three
  22. Minimum Time Visiting All Points
  23. Hexspeak
  24. Subtract the Product and Sum of Digits of an Integer
  25. Convert Binary Number in a Linked List to Integer

Info Cache

  1. Valid Sudoku
  2. Design Tic-Tac-Toe
  3. Find Winner on a Tic Tac Toe Game

Design

  1. Encode and Decode Strings (Chunked Transfer Encoding)
  2. Zigzag Iterator
  3. Design Snake Game
  4. Design Hit Counter
  5. Design Circular Deque
  6. Design HashSet
  7. Design HashMap
  8. Maximum Frequency Stack

Intervals

  1. Meeting Rooms II
  2. Range Addition
  3. Non-overlapping Intervals
  4. Minimum Number of Arrows to Burst Balloons
  5. My Calendar I
  6. My Calendar II
  7. Maximum Profit in Job Scheduling
  8. Remove Interval
  9. Remove Covered Intervals

Find Missing/Duplicate Number

  1. Find the Duplicate Number
  2. Set Mismatch

Simulation

  1. Candy Crush
  2. Pour Water
  3. Array Transformation
  4. Cells with Odd Values in a Matrix
  5. Find Winner on a Tic Tac Toe Game

Prefix Sum

  1. Maximum Size Subarray Sum Equals k
  2. Random Pick with Weight
  3. Find Pivot Index
  4. Maximum Sum of Two Non-Overlapping Subarrays
  5. Maximum Side Length of a Square with Sum Less than or Equal to Threshold
  6. Matrix Block Sum

Synchronization

  1. Traffic Light Controlled Intersection

Boyer–Moore majority vote algo

  1. Majority Element
  2. Majority Element II
  3. Online Majority Element In Subarray

About

Solutions of LeetCode problems


Languages

Language:Java 100.0%