Skip to content

Instantly share code, notes, and snippets.

@cmattey
Last active August 28, 2019 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmattey/5bab706de8bd125be0cbedeecb353ef9 to your computer and use it in GitHub Desktop.
Save cmattey/5bab706de8bd125be0cbedeecb353ef9 to your computer and use it in GitHub Desktop.
from collections import defaultdict
import heapq
def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int, K: int) -> int:
flight_map = defaultdict(list)
for start, end, price in flights:
flight_map[start].append([end,price])
heap = [(0, -1, src)] #price, stops, city
# We use the first argument to be the price, since the heapq library in python will heapify the data using the first argument by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment