LeetCode Record
  • Sort
    • 912 quick sort
    • 148 sort list
    • 179 largest number
    • 75 sort colors
    • 215 kth largest element in array
    • 4 Median of 2 sorted array
  • linked list
    • 160 intersection of 2 linked lists
    • 92 reverse linked list2
    • 😐328 Odd even list
  • Queue
    • 1429 first unique number
    • 54 Spiral Matrix
  • Stack (some may involve tree map)
    • 😲716 Max Stack
    • 155 Min Stack
    • 895 maximum frequency stack
    • 1472 Design Browser History
    • 🙃1209 remove all adjacent duplicates in string
    • 🙃1249 minimum remove to make valid parentheses
  • Priority Queue
    • 😲88 merge sorted array
    • 295 find median from data stream
    • 767 reorganize string
    • 1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
  • Map/Set
    • 😮128 longest consecutive sequence
    • 😲380 insert delete getrandom O(1)
    • 348 Design tic tac toe
  • Binary Search
    • 😟33 search in rotated sorted array
    • 1095 find in mountain array
    • 540 single element in a sorted array
    • 😮240 search a 2D matrix II
    • 🥴644 maximum average subarray II
    • 528 random pick with weight
    • 1300 Sum of mutated array closest to target
    • 1060 missing elements in sorted array
    • 😷1062 longest repeating substring
    • 1891 cutting ribbons
    • 🙃410 split array largest sum
  • 2 pointer (including sliding window)
    • 🙃409 longest palindrome
    • 5 longest palindrome substring
    • 16 3 sum closest
    • 18 4 sum
    • 😮454 4sum II
    • 277 find the celebrity
    • 11 Container with most water
    • 42 Trapping rain water
    • 283 move zeros
    • 26 remove duplicates from sorted array
    • 340. Longest Substring with At Most K Distinct Characters
    • 🧐395 longest substring with at least k repeating characters
    • 🫥76 minimum window substring
    • 424 longest repeating character replacement
    • 😕1658 Minimum Operations to Reduce X to Zero
    • 2537 count the number of good subarrays
    • 15 3sum
  • BFS (some may be solved by union find)
    • 😅297. Serialize and Deserialize Binary Tree
    • 314 binary tree vertical order traversal
    • 🤣133 clone graph
    • 😲323 Number of Connected Components in an Undirected Graph (using union find~)
    • 😮130 surrounded regions
    • 752 open the lock
    • 😫815 Bus Routes
    • 😮542 01 Matrix
    • 1293. Shortest Path in a Grid with Obstacles Elimination
    • 417 pacific atlantic water flow
  • topological sort
    • 207. Course Schedule
    • 😵444 sequence reconstruction
    • 269 alien dictionary
    • 😲310 minimum height tree
    • 😑366 find leaves of binary tree
  • BST binary search tree
    • 98 validate binary search tree
    • 270. Closest Binary Search Tree Value
    • 333 Largest BST subtree
    • 😑285 inorder successor in BST
    • 😕510 inorder successor in BST II
  • DFS / Backtracking
    • 236. Lowest Common Ancestor of a Binary Tree
    • 572 subtree of another tree
    • 987 verticle order traversal of a binary tree
    • 863 All nodes in distance k in binary tree
    • 😳1110 Delete nodes and return forest
    • 341 flatten nested list iterator
    • 😬394 decode string
    • 51 N queens
    • 🥺291 word pattern II
    • 126 word ladder II
    • 93 restore ip address
    • 22 generate parenthesis
    • 856 score of parentheses
    • 🙃301 remove invalid parentheses
    • 🤯37 solve sudoku
    • 😁212 word search II
    • 1087 brace expansion
    • 399 Evaluate Division
    • 1274 numbers of ships in a rectangle
    • 1376 Time Needed to Inform All Employees
    • 694 number of distinct islands
    • 🙁Palindrome partitioning
    • 39 combination sum
    • 40 combination sum II
    • 216 combination sum III
    • 😕377 combination sum IV
    • 90 subsets II
    • 😁47 permutation II
    • 😑698. Partition to K Equal Sum Subsets
    • 😀403 frog jump (记忆化搜索)
    • ☹️longest increasing path in matrix
    • 437 path sum III
  • DP
    • 300 Longest increasing subsequence
    • 368. Largest Divisible Subset
    • 🤯1235 max profit in job scheduling
    • 1335 minimum difficulty of a job schedule
    • 😕1216 valid palindrome III
    • 🙁97 interleaving string
    • 472 concatenated words
    • 53 maximum subarray
    • 85 Maximal Rectangle
    • 122. Best Time to Buy and Sell Stock II
    • 221 Maximal Square
    • 518 coin change II (01背包)
    • 115 distinct subsequences
    • 198 House robber
    • 213. House Robber II
    • 740. Delete and Earn
  • Prefix sum
    • 53. Maximum Subarray
    • 😟304. Range Sum Query 2D - Immutable
    • 1031 maximum sum of two non overlapping subarrays
    • 😁523 continuous subarray sum
  • Union find
    • 😇721 account merge
    • 547 number of provinces
    • 737 sentence similarity
  • Swipe Line
    • 253 Meeting rooms II
    • 2402 Meeting room III
    • 🥹218 The Skyline Problem
    • 759 Employee free time
    • 56. Merge Intervals
  • Segment tree
    • 699 falling squares
    • 315 Count of smaller numbers after self
    • 😯327 Count of Range Sum
  • Monotonic Stack/Queue
    • 84 Largest Rectangle in Histogram
    • 85 Maximal rectangle
    • 907 Sum of Subarray Minimums
    • 901 online stock span
    • 503 Next greater element II
    • 239 Sliding Window Maximum (mono deque)
    • 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (mono deque)
    • 42 Trapping rain water
  • Trie
    • 208. Implement Trie (Prefix Tree)
  • TreeMap
    • 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
    • 729. My Calendar I
    • 218 The Skyline Problem
  • Sessions
    • BFS
      • Avoiding Bears
      • 🥲Taking courses
Powered by GitBook
On this page

topological sort

记住箭头方向永远是pre -> next,一般都会维护两个map,一个是next的indegrees,另一个是pre的所有next

topological sort 一般不分层,可以通过把queue换成priority queue来施加一个general的全局default order

example: alien dictionary: ax < by,x和y的order不明确,此时default成自然字母序,可以通过把x和y放进priority queue来解决。

Previous417 pacific atlantic water flowNext207. Course Schedule

Last updated 28 days ago