LeetCode 797. All Paths From Source to Target Explanation and Solution

preview_player
Показать описание
OUTLINE:
0:00 - Reading and understanding the question
1:16 - Analysis
2:21 - Live coding and explaining

Remember to like this video and subscribe to my channel! :D

Thanks in advance. :D

Рекомендации по теме
Комментарии
Автор

Great solution! Thank you for sharing :)

elliotho
Автор

Awesome solution...the most concise one!

shubhamkiingale
Автор

I am bit confused are we not supposed to have fixed size number of element in each row of the 2 dimensional array. How can graph[0] and graph[1] have different number of elements?

chaithanyakanumolu
Автор

Thanks so much for making the video. Sweet and simple explanation!

weiqing
Автор

my python conversion following happygirlzt backtracking template

class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
rs = []
def backtracking(rs:[[int]], tmp:[int], cur_indx:int):
# (a) base case
if cur_indx == len(graph) - 1:
rs.append(list(tmp))
return
# (b) recursive case "from graph[cur_indx]"
for next_idx in graph[cur_indx]:
# 1. choose
tmp.append(next_idx)
# 2. recursively explore "using next_idx"
backtracking(rs, tmp, next_idx)
# 3. un-choose
tmp.pop()
backtracking(rs, [0], 0)
return rs

aunnfriends
Автор

Standard recursion, can you also come up with the iterative DFS solution?

riveridea