Data Structure & Algorithm: Level-1 Problem #29. Leaves Weight

Given a binary tree, each node has a weight. A leave note is a one without any child node. Find out the total weight of all the right leaves.

For the binary tree shown below, the total weight of right leaves (highlighted in yellow) is: 8 + 18 + 33 = 59

Right Leaves


数据结构和算法:初级练习题 #29 – 叶子重量


给定一颗二叉树,每个节点都有各自的重量,如果一个节点没有子节点就是叶节点。计算二叉树所有右叶节点的总重量。

如上图所示的二叉树,右叶节点(黄色)总共有三个,总重量是:8 + 18 + 33 = 59。


Python Solutions

Leaves Weight