feb

round2: 1. 打印从根到叶子的路径,分别递归,非递归。follow up,pretty print the path,比如下面例子。感觉是vertical traverse的变种

      A

     / \

    B   C

  /    / \

 D    E   F

// ABD goes to

  A
 B
D

// ACE goes to:

A
 C
E

// ACF goes to:

A
 C
  F

round2: 2. 最长等差数列, [1,3,-10,5,-22,4,9,7], 结果中的元素要按原数组中的顺序,差可以是正,负或者0。这个例子最长是【1,3,5,7】,9不能包括因为原数组中9在7前出现。

给了个很怂的N^2解法,用到了字典。

Pretty print the path

Last updated

Was this helpful?