일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로젝트
- FIT XR
- Daily Challenge
- 스탭퍼
- 매일
- 잡생각
- 영어공부
- 쓰릴오브파이트
- 3줄정리
- 만화도
- Problem Solving
- realclass
- 파비최
- 리얼 클래스
- 화상영어
- leetcode
- 월간
- Writing
- 괜찮음
- 뭐든
- 읽기
- 30분
- 영어원서읽기
- 미드시청
- 개발자
- 운동
- English
- 링피트
- 사이드
- 10분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.06.02 Today's Challenge 본문
https://leetcode.com/problems/shortest-path-in-binary-matrix/solutions/
Shortest Path in Binary Matrix - LeetCode
Can you solve this real interview question? Shortest Path in Binary Matrix - Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. A clear path in a binary matrix is a path from
leetcode.com
예상대로 DFS로 푸는 문제!
class Solution:
def maximumDetonation(self, bombs: List[List[int]]) -> int:
gr = collections.defaultdict(list)
n = len(bombs)
for i in range(n):
for j in range(n):
if i == j:
continue
xi, yi, ri = bombs[i]
xj, yj, _ = bombs[j]
if ri ** 2 >= (xi - xj) ** 2 + (yi - yj) ** 2:
gr[i].append(j)
def dfs(cur, visited):
visited.add(cur)
for neib in gr[cur]:
if neib not in visited:
dfs(neib, visited)
return len(visited)
answer = 0
for i in range(n):
visited = set()
answer = max(answer, dfs(i, visited))
return answer
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.06.04 Today's Challenge (0) | 2023.06.04 |
---|---|
2023.06.03 Today's Challenge (0) | 2023.06.03 |
2023.06.01 Today's Challenge (0) | 2023.06.01 |
2023.05.31 Today's Challenge (0) | 2023.05.31 |
2023.05.30 Today's Challenge (0) | 2023.05.30 |
Comments