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:
來(lái)源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/count-nodes-equal-to-sum-of-descendants
著作權(quán)歸領(lǐng)扣網(wǎng)絡(luò)所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系官方授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。
2. 解題
- 自底向上,后序遍歷
360 ms 195.4 MB C++
我的CSDN博客地址 https://michael.blog.csdn.net/
長(zhǎng)按或掃碼關(guān)注我的公眾號(hào)(Michael阿明),一起加油、一起學(xué)習(xí)進(jìn)步!
總結(jié)
以上是生活随笔為你收集整理的LeetCode 1973. Count Nodes Equal to Sum of Descendants(DFS)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 气象数据领航无人飞行器线路优化大赛解决方
- 下一篇: MapReduce 编程实践:统计对象中