JiaqiLiu / LeetCode-Summary

My personal summary of LeetCode problems, including solution optimization methods and some thoughts on it.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LeetCode-Summary

General Methods & Tips

  1. Binary Search Coding Principles
  2. XOR Swapping Method
  3. GCD

Catalog

Array

  1. k Sum
    2 Sum--exactly one solution/no duplicates

    • HashMap:O(n) <=no duplicate
    • Sort+Two Pointers:O(nlogn); if sorted:O(n)

    3 Sum-contains duplicates

    • Sort+Two Pointers:O(n^2)

    3 Sum Closest

    • Sort+Two Pointers:O(n^2), cannot use hashmap since it looks for the closest answer instead of the exact one.

    4 Sum

    • Sort+Two Pointers:O(n^3),some modifications to avoid useless computations
    • 'Two Sum' solution:O(n^2*logn)
  2. Rotation   -to be continued
    Rotate Array

  3. Pascal's Triangle II

  4. Contains Duplicate -not finnished yet
    Contains Duplicate I
    Contains Duplicate II

  5. Intersection of Two Arrays -to be continued
    Intersection of Two Arrays I

String

  1. String

Math

  1. Math Solutions
    Gray Code
    Rotate Function

LinkedList

  1. Fast & Slow Pointers
    Rotate List

Dynamic Programming

  1. Best Time to Buy and Sell Stock -to be continued
    Best Time to Buy and Sell Stock
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock with Cooldown
  2. Majority Element
  3. Dynamic Programming - 2D -to be continued
    Minimum Path Sum

Binary Search

  1. Find Peak Element -to be continued

Heap

  1. Heap
    K-th Smallest Element in a Sorted Matrix
    Find K Pairs with Smallest Sums

Backtracking

  1. Classic Backtrackings
    Palindrome Partitioning
    Combinations
    Combination Sum
    Combination Sum II
    Combination Sum III
    Permutation
    Permutation II
    Subsets
    Subsets II

  2. Backtracking
    Generate Parentheses
    Letter Combinations of a Phone Number
    Binary Watch
    Word Search

Tree

  1. Tree Traversal
    Binary Tree Preorder Traversal
    Binary Tree Inorder Traversal
    Binary Tree Postorder Traversal
    Binary Tree Level Order Traversal
    Binary Tree Zigzag Level Order Traversal

About

My personal summary of LeetCode problems, including solution optimization methods and some thoughts on it.