Question is asking for longest path which has same node value
combine both left and right
so the path is
leftmost 4 -> middle 4 -> right down 4
as all node values is 4 we have to consider all
Hope this will help.
second last line, why do you need + res at the end? it looks like you are adding emty string at the end ? but in a loop res will change, so in second iteration you will not get empty string? please let me know if you need it for specific reason. for (String dir : stack) res = "/" + dir + res;
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.