일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Substring with Concatenation of All Words
- Protocol
- kaggle
- shiba
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- Class
- Python Implementation
- Decorator
- 43. Multiply Strings
- 프로그래머스
- concurrency
- Regular Expression
- 30. Substring with Concatenation of All Words
- Python
- attribute
- t1
- 315. Count of Smaller Numbers After Self
- Python Code
- DWG
- 컴퓨터의 구조
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- LeetCode
- 운영체제
- 시바견
- 밴픽
- Generator
- iterator
- data science
Archives
- Today
- Total
Scribbling
LeetCode: 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance 본문
Computer Science/Coding Test
LeetCode: 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance
focalpoint 2021. 8. 10. 21:57class Solution:
def findTheCity(self, n: int, edges: List[List[int]], distanceThreshold: int) -> int:
INF = int(1e9)
distance = [[INF] * (n) for _ in range(n)]
for i in range(n):
distance[i][i] = 0
for edge in edges:
u = edge[0]
v = edge[1]
w = edge[2]
distance[u][v] = w
distance[v][u] = w
for k in range(n):
for a in range(n):
for b in range(n):
distance[a][b] = min(distance[a][b], distance[a][k] + distance[k][b])
num_reachable_list = []
for i in range(n):
num_reachable = 0
for j in range(n):
if distance[i][j] <= distanceThreshold:
num_reachable += 1
num_reachable_list.append(num_reachable)
num_min = min(num_reachable_list)
for idx in range(n-1, -1, -1):
if num_reachable_list[idx] == num_min:
return idx
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 5. Longest Palindromic Substring (0) | 2021.08.12 |
---|---|
LeetCode: 787. Cheapest Flights Within K Stops (0) | 2021.08.12 |
LeetCode: 3. Longest Substring Without Repeating Characters (0) | 2021.08.11 |
LeetCode: 743. Network Delay Time (0) | 2021.08.10 |
LeetCode: 2. Add Two Numbers (0) | 2021.08.10 |