You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/easy/112_path_sum.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,7 @@
7
7
8
8
Keeping track of the sum as we go down the tree is one way.
9
9
So that when we reach a leaf node (no children), we can check the current sum against the target sum.
10
-
Since its recursion, the current sum before the recursion call would be used so we don't need to subtract from the current sum.
11
-
We let recursion do that for us.
10
+
Since its recursion, the current sum before the recursion call would be reused if we hit a dead end, so we don't need to do any subtraction from the current sum, we let recursion do that for us.
12
11
13
12
Since we will be visiting all the nodes, the runtime is O(N).
14
13
In the worst case, we would have to have every node on the stack if the whole tree was just a linked list, space would be O(N).
0 commit comments