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. poj 3648 线段树成段更新

    线段树成段更新需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候.延迟标记的意思是:这个区间的左右儿子都需要被更新,但是当 ...

  2. Error Code: 1055 incompatible with sql_mode=only_full_group_by

    OperationalError at / (1055, "Expression #1 of ORDER BY clause is not in GROUP BY clause and co ...

  3. Dapper Sqlpara where in

    Mark一下:string sql = "SELECT * FROM SomeTable WHERE id IN @ids" var results = conn.Query(sq ...

  4. vue2.0中怎么获取元素

    在元素上添加 v-el:food-wrapper (不用驼峰的写法) vue1版本 报错: vue2版本 (vue2把vue1中的 v-el 改为了 ref vue1 v-el:foods-wrapp ...

  5. AngularJS的添加操作和列表操作

    代码下载:https://files.cnblogs.com/files/xiandedanteng/agsAddList.rar 添加成员页面图示: 添加成员页面代码: <%@ page la ...

  6. ZT:成熟是一种明亮而不刺眼的光辉

    成熟是一种明亮而不刺眼的光辉, 一种圆润而不腻耳的音响, 一种不再需要对别人察言观色的, 一种终于停止向周围申诉求告的大气, 一种不理会哄闹的微笑, 一种洗刷了偏激的冷漠, 一种无需声张的厚实, 一种 ...

  7. 【AngularJS】【01】简介

    ※文件引自OneDrive,有些人可能看不到

  8. 一个免费的API-手机号码归属地接口

    手机号码归属地接口:根据手机号码或手机号码的前7位,查询手机号码归属地信息,包括省份 .城市.区号.邮编.运营商和卡类型. 接口文档:https://www.juhe.cn/docs/api/id/1 ...

  9. vue Object.freeze() 优化

    参考自:https://segmentfault.com/a/1190000006191558 Object.freeze()是ES5新增的特性,可以冻结一个对象,防止对象被修改. vue 1.0.1 ...

  10. JSP简单练习-用Servlet获取表单数据

    // javaBean代码 package servlet; import java.io.*; import javax.servlet.*; import javax.servlet.http.* ...