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 ...
随机推荐
- windows核心编程 DLL技术 【转】
注:本文章转载于网络,源地址为:http://blog.csdn.net/ithzhang/article/details/7051558 本篇文章将介绍DLL显式链接的过程和模块基地址重定位及模块绑 ...
- vim g s 替换区别
vim g s 替换区别 PS:一篇好文收藏备用,今天用它解决了一个大问题. 发信人: vale (浅谷), 信区: VIM标 题: global命令详解 发信站: 水木社区 (Fri Ju ...
- SSO 单点登录简单流程(cas)
配置服务端(链接数据库) 第一步: 下载cas-server端,解压开, 将中的解压开,将该包中的内容放入cas文件夹(新建文件夹)中 然后将这个文件夹放入到服务端的服务器(tomcat)中 将解压开 ...
- 版本号控制软件:TortoiseSVN高速上手
百度百科对于SVN的一点解释: TortoiseSVN是Subversion版本号控制系统的一个免费开源client,能够超越时间的管理文件和文件夹.文件保存在中央版本号库,除了能记住文件和文件夹的每 ...
- 利用动态图添加Loading动画
opacity:CSS3中的属性,调节透明度,一般取值0.5 添加思想: 1.对超链接添加点击事件,通过new {@onclick="showLoading()"} Html.Ac ...
- oracle 使用job定时自动重置sequence
一.赋予用户创建和删除sequence的权限 grant create any sequence to user_name; grant drop any sequnce to user_name; ...
- Linux ps 命令查看进程启动及运行时间
引言 同事问我怎样看一个进程的启动时间和运行时间,我第一反应当然是说用 ps 命令啦.ps aux或ps -ef不就可以看时间吗? ps aux选项及输出说明 我们来重新复习下ps aux的选项,这是 ...
- android位置布局
fill_parent 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间.这跟Windows控件的dockstyle属性大体一致.设置一个顶部布局或控件为 ...
- web 表单方式上传文件方法(不用flash插件)
原理:使用表单的input type="file"标签,通过ajax提交表单请求,后台获取请求中的文件信息,进行文件保存操作 由于我测试用的做了一个上传文件和上传图片方法,所以我有 ...
- php的一个小坑,输出不了json_encode
明明是旧代码,怎么换个地方就不执行了.一开始怀疑是Php的版本. 最后才知道是我的编辑器nodepad++给坑了.或许不是nodepad++的坑.总之,需要转化为utf-8格式编码即可