Backtracking 1 - Additional States - Backtracking / Additional States

The template (at least for Java) seems inconsistent with the text: “we are keeping one or more additional states as dfs parameters”

But in the template (for Java), additional states are not in parameter list, can the team look into this?

Hi sea, you are right. We updated it. Thanks!

Hi , I wonder why this line of code should act like this.
// add a copy of the path to the result
why do you need to explicitly construc a new vector?
Is it necessary?

you need to make a deep copy otherwise future calls would mutate it and you end up with a result vector with each element referencing the same vector

Actually, we pass vector by value, so it is already copied on each invocation of dfs. So it is not necessary to copy it again. Also, we could move it to avoid copying into res:


In the java version, line 9 is missing the “path” parameter.
dfs(startIndex + edge.length(), path, res, […additional states]);