package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev

# README

654. Maximum Binary Tree

Solution idea

Binary Tree - Post-order Traversal

  • 当前层先找到input nums里的最大的值和它的index
  • 左子树构建需要 nums[:index]
  • 右子树构建需要 nums[index+1:]
  • 用input nums里的最大的值构建当前层的node 并 链接上左、右子树

Time complexity = $O(n^2)$ because traversing every node needs $O(n)$ and constructing each node will loop nums by $O(n)$

Resource

东哥带你刷二叉树(构造篇)

代码随想录-654.最大二叉树