257. Binary Tree Paths

# Easy

Not easy. Hard to think. Two cases are needed to consider in helper function.

  1. root doesn't have any child, then this path completes

  2. root is empty, then this path is invalid.

List1 = [1, 2, 3], List2 = [2, 4, 6]. List1 + List2 = [1, 2, 3, 2, 4, 6]

So in the implementation below, List1 = ['1->2->5'], List2 = ['1->3'], then List1+List2 = [['1->2->5'], ['1->3']].

Time complexity = O(n)O(n) , traversal all nodes.

Last updated

Was this helpful?