Move stones in binary tree


  • 0
    C

    Given a binary tree, each node has a unique tag (say node0, node1, etc.), as well as a positive number N, let's say that number represents how many stones stored in that node. For each node, we can move 1 stone to its parent or children at one time.
    Now we know that count of nodes == count of stones, so we can finally move stones between nodes to make each node only has 1 stone. Write a function to find and print the best solution has minimal moves to make each node has 1 stone.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.