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的更多相关文章

  1. 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 ...

  2. [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 ...

  3. [转]Data Structure Recovery using PIN and PyGraphviz

    Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...

  4. LeetCode 笔记27 Two Sum III - Data structure design

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  5. [Data Structure] Tree - relative

    Segment Tree First, try to build the segment tree. lintcode suggest code: Currently recursion recomm ...

  6. [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 - ...

  7. [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  8. ✡ 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 - ...

  9. LeetCode Two Sum III - Data structure design

    原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...

随机推荐

  1. mac 下mysql常用命令

    是那种单独安装的mysql 启动: /usr/local/mysql/bin/mysql -u root -p

  2. GEOS 使用的例子

    typedef Coordinate PT;geos::geom::Geometry* CGlbGlobePolygonSymbol::Interection(CGlbPolygon *geom, C ...

  3. 在容器内执行go编译程序的坑

    如果你编译了一个go程序,让后把它放到容器里面.很多时候这个程序都会无法执行,大概的样子是: /tmp # ls pub sub /tmp # ./pub /bin/ash: pub: not fou ...

  4. C++ 关于类与对象在虚函数表上唯一性问题 浅析

    [摘要] 非常多教材上都有介绍到虚指针.虚函数与虚函数表.有的说类对象共享一个虚函数表,有的说,一个类对象拥有一个虚函数表.还有的说,不管用户声明了多少个类对象,可是,这个VTABLE虚函数表仅仅有一 ...

  5. JDK8 下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    JDK8 下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 安装时最好在 ...

  6. 【Python】创建和使用类

    面向对象编程是最有效的软件编写方法之一 创建Dog类 class Dog(): '''一次模拟小狗的简单测试''' def __init__(self,name,age): self.name = n ...

  7. layui-概念-入门-总结

    layui教程:http://www.dosrun.com/layui/ 获得 Layui你可以在官网首页下载到 Layui 的最新版,也可以通过 GitHub得到Layui的开源包.目前只同步维护这 ...

  8. Codeforces Round #263 (Div. 2) proB

    题目: B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input ...

  9. 企业级API设计

    最近对service的API设计,在team内有些讨论,主要集中在API是足够抽象.通用好呢, 还是具体.易用好? 其实这个是要折衷的,通用的好处是以后更改API的可能性小,但坏处是想要通用,里面的字 ...

  10. linux中MACHINE_START&END在9g10ek上实现

    在linux的板卡初始化文件中有machine的相关定义 //arch/arm/mach-at91/board-sam9261ek.c MACHINE_START(AT91SAM9G10EK, &qu ...