일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 3줄정리
- 운동
- 미드시청
- 리얼 클래스
- 프로젝트
- 영어공부
- 매일
- Daily Challenge
- 개발자
- 화상영어
- 10분
- 30분
- Problem Solving
- 월간
- 읽기
- 스탭퍼
- FIT XR
- 쓰릴오브파이트
- leetcode
- 괜찮음
- 파비최
- realclass
- 뭐든
- 잡생각
- 사이드
- English
- Writing
- 영어원서읽기
- 만화도
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.22 Today's Challenge 본문
https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/
Minimum Score of a Path Between Two Cities - LeetCode
Can you solve this real interview question? Minimum Score of a Path Between Two Cities - You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that
leetcode.com
BFS로 풀면 되는 문제
class Solution:
def minScore(self, n: int, roads: List[List[int]]) -> int:
g = defaultdict(dict)
for u, v, w in roads:
g[u][v] = g[v][u] = w
ms = float('inf')
visited = set()
qu = deque([1])
while qu:
node = qu.popleft()
for adj, score in g[node].items():
if adj not in visited:
qu.append(adj)
visited.add(adj)
ms = min(ms, score)
return ms
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.24 Today's Challenge (0) | 2023.03.24 |
---|---|
2023.03.23 Today's Challenge (0) | 2023.03.23 |
2023.03.21 Today's Challenge (0) | 2023.03.21 |
2023.03.20 Today's Challenge (0) | 2023.03.20 |
2023.03.19 Today's Challenge (0) | 2023.03.19 |
Comments