Data Structure Binary Tree: Check for Children Sum Property in a Binary Tree
http://www.geeksforgeeks.org/check-for-children-sum-property-in-a-binary-tree/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std; struct node {
int data;
struct node *left, *right;
node() : data(), left(NULL), right(NULL) { }
node(int d) : data(d), left(NULL), right(NULL) { }
}; void print(node *node) {
if (!node) return;
print(node->left);
cout << node->data << " ";
print(node->right);
} bool isSumproperty(node *root) {
if (!root || !root->left && !root->right) return true;
int sum = ;
sum += root->left != NULL? root->left->data : ;
sum += root->right != NULL? root->right->data : ;
return sum == root->data && isSumproperty(root->left) && isSumproperty(root->right);
} int main() {
struct node* root = new node();
root->left = new node();
root->right = new node();
root->left->left = new node();
root->left->right = new node();
root->right->right = new node();
if (isSumproperty(root)) cout << "yes" << endl;
else cout << "NO" << endl;
return ;
}
Data Structure Binary Tree: Check for Children Sum Property in a Binary Tree的更多相关文章
- Data Structure Binary Tree: Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
		
http://www.geeksforgeeks.org/convert-an-arbitrary-binary-tree-to-a-tree-that-holds-children-sum-prop ...
 - [Algorithms] Tree Data Structure in JavaScript
		
In a tree, nodes have a single parent node and may have many children nodes. They never have more th ...
 - [转]Data Structure Recovery using PIN and PyGraphviz
		
Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...
 - LeetCode 笔记27 Two Sum III - Data structure design
		
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
 - [Data Structure] Tree - relative
		
Segment Tree First, try to build the segment tree. lintcode suggest code: Currently recursion recomm ...
 - [leetcode]170. Two Sum III - Data structure design两数之和III - 数据结构设计
		
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
 - [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计
		
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
 - ✡    leetcode   170. Two Sum III - Data structure design  设计two sum模式 --------- java
		
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
 - LeetCode Two Sum III - Data structure design
		
原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...
 
随机推荐
- VS2010 MFC中 单独添加ODBC数据库记录集类(CRecordset)方法
			
基于VS2010 MFC的项目是之前建好的,后来需要添加数据库. 方法分享于此. 1. 打开自己的项目,项目->添加类. 2. 选MFC ODBC使用者,点右下角的添加. 3. 点数据源. / ...
 - 查看网络port占用
			
Linux和Mac下通用: 1. 利用 netstat 查看网络状态命令: netstat -an|grep port号 2. 利用list open file 命令打开文件(一切都是文件. 包含网 ...
 - 如何把VBS转换为EXE文件
			
如下所示,我想要做一个把360网速测试剥离开来的绿色版,有一个TestSpeed.bat命令,双击之后去执行了360AppLoader.exe,并且会调用netmon文件夹的NetSpeed.dll文 ...
 - apache默认路径
			
读启动文件 /etc/inid.d/httpd 默认web路径 /var/www/html inux下Apache PHP MYSQL 默认安装路径 apache:如果采用RPM包安装,安装路径应在 ...
 - 【VBS】发邮件
			
Sub SendMail(pMailFrom, pMailTo, pSubject, pMailBody, pMailSmtpServer) On Error Resume Next Dim objS ...
 - widget 常用UI控件介绍
			
一.单选框 单选框实例程序: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
 - Maven零散笔记——配置Nexus
			
安装&配置Nexus 解压后,应该获得如下目录结构: nexus-2.0.6是nexus服务主目录 sonatype-work是真正的仓库,同时包含了nexus的配置,如定时任务.用户配置等 ...
 - Boost.Asio c++ 网络编程翻译(11)
			
*_at方法 这些方法在一个流上面做随机存取操作.你来指定read和write操作从什么地方開始(offset): async_read_at(stream, offset, buffer [, co ...
 - 摩根大通银行被黑客攻克, ATM机/网银危在旦夕,winxp退市灾难来临了
			
winxp4月退市到如今还不到半年,就出现故障了 7600多万个消费者银行账户被黑.此外还有700万个小企业账户的信息也被黑客窃取,这个算不算灾难呢?假设等到银行业彻底崩溃,资金彻底丧失,那不仅仅是灾 ...
 - ubuntu 12.10 笔记
			
笔记 more ec_unitouch.log |grep Thread-4 筛选日志 打开命令行终端 ctrl + alt + t 查看版本号 : sudo lsb_release -a t ...