일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- Decorator
- shiba
- 프로그래머스
- 315. Count of Smaller Numbers After Self
- Python Code
- 운영체제
- iterator
- Python
- 컴퓨터의 구조
- 파이썬
- 715. Range Module
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- concurrency
- Generator
- Python Implementation
- 30. Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- DWG
- Class
- LeetCode
- 시바견
- Regular Expression
- t1
- data science
- 43. Multiply Strings
- Protocol
- attribute
- kaggle
- Convert Sorted List to Binary Search Tree
Archives
- Today
- Total
목록787. Cheapest Flights Within K Stops (1)
Scribbling
LeetCode: 787. Cheapest Flights Within K Stops
src로부터 특정 dst까지의 최단 거리를 묻는 문제로, 다익스트라 알고리즘을 먼저 떠올릴 수 있다. 기본적인 형태의 다익스트라 알고리즘은, priority queue에 "최단 거리가 갱신되는 경우"를 추가한다. 하지만 이 문제는 "이동 횟수 제한"이 있으므로, 이를 수정해야한다. 즉, priority queue에 "최단 거리가 갱신되는 경우"를 추가하는 것이 아니라, "추가적으로 이동 가능한 경우"를 모두 추가할 필요가 있다. 이를 코드로 구현하면 아래와 같다. import heapq class Solution: def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int: INF = int..
Computer Science/Coding Test
2021. 8. 12. 13:26