Skip to content

Latest commit

 

History

History
10 lines (10 loc) · 527 Bytes

note0979.md

File metadata and controls

10 lines (10 loc) · 527 Bytes

Leetcode (979. Distribute Coins in Binary Tree)[https://leetcode.com/problems/distribute-coins-in-binary-tree/]

  • Type: binary tree
  • Approach:
    • dfs + bottom-up
    • For each node, return cur_node.val+left+right-1, for we have totally cur_node.val+left+right coins at the current node, we need to do (total coins - 1) numbers of operations to distribute coins; as for result, we accumulatively add abs(left)+abs(right) to the result.
  • Boundary and results:
    • If not node, return 0
  • Complexity:
    • Time: O(n)
    • Space: O(1)