LeetCode 1973. Count Nodes Equal to Sum of Descendants(DFS)
生活随笔
收集整理的這篇文章主要介紹了
LeetCode 1973. Count Nodes Equal to Sum of Descendants(DFS)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 題目
- 2. 解題
1. 題目
Given the root of a binary tree, return the number of nodes where the value of the node is equal to the sum of the values of its descendants.
A descendant of a node x is any node that is on the path from node x to some leaf node.
The sum is considered to be 0 if the node has no descendants.
Example 1:
Example 2:
Example 3:
來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/count-nodes-equal-to-sum-of-descendants
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
- 自底向上,后序遍歷
360 ms 195.4 MB C++
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode 1973. Count Nodes Equal to Sum of Descendants(DFS)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 气象数据领航无人飞行器线路优化大赛解决方
- 下一篇: MapReduce 编程实践:统计对象中