leetcode.979.distribute-coins-in-binary-tree

command
v0.0.0-...-a94f1ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

README

Distribute Coins in Binary Tree

思路

DFS 深度优先搜索

每个节点只能保留一个硬币,不管是移入还是移出,都需要移动当前硬币 - 1 次,从最深处开始移动,每次移动的数都累计在父节点上,父节点需要移动的次数是自身硬币数 + 左边移动的硬币数 + 右边移动的硬币数 - 1

Documentation

Overview

*

  • Definition for a binary tree node.
  • type TreeNode struct {
  • Val int
  • Left *TreeNode
  • Right *TreeNode
  • }

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL