Leetcode 2385 - Amount of Time for Binary Tree to Be Infected

題目

Problem#

給你一個 binary tree 的 root 上面的值都不重複,另外給你一個數字 start,問你從該數字的 node 為 root,最大深度為多少?

測資限制#

  • $1 \le n \le 10^5$
  • $1 \le val \le 10^5$

想法#

遍歷整個二元樹之後建成無向圖,接著再從起點開始遍歷找最大深度即可

AC Code#

  • 時間複雜度: $\mathcal{O}(n)$
  • 空間複雜度: $\mathcal{O}(n)$

心得#

原本想寫不建圖的,但後來放棄ㄌ