Back to course home
0% completed
Vote For New Content
All Paths for a Sum
Siew Lee
Sep 2, 2023
allPaths.append(list(currentPath)) <- why do we add list() here?
1
0
Comments
Comments
Prateek Sethi2 years ago
This is done to add a copy of the list currentPath instead of a reference to the list currentPath.
currentPath is a list that is modified in-place. When you append it to allPaths - allPaths.append(currentPath), you're essentially appending a reference to the same list,...
On this page