반응형

Computer Science/LeetCode 20

797. All Paths From Source to Target

All Paths From Source to Target - LeetCode DFS든 BFS든 상관 없고DFS는 할 거면 end state 아닐 때 pop하는 걸 기억해야하고,BFS는 그거랑 상관없이 path의 맨 뒤 node를 기준으로 해서 queueing하는 것 정도? ##### by DFSclass Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: n = len(graph) target = n - 1 res = [] path = [] def dfs(node): ## do smthing p..

2101. Detonate the Maximum Bombs

https://leetcode.com/problems/detonate-the-maximum-bombs/ adjacent를 표현하는 그래프를 먼저 그리고 그에 맞도록 DFS를 해주면 된다. 그리고 한 칸 이동 = stack pop 할 때마다 카운터 +1 하면 된다. class Solution: def maximumDetonation(self, bombs: List[List[int]]) -> int: n = len(bombs) adj = [[] for _ in range(n)] # Make Graph: i can bomb out j? for i in range(n): xi, yi, ri = bombs[i] r..

반응형