/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int sumNumbers(TreeNode* root) {
if(root == NULL) return ;
int res = ;
DFS(root,res,);
return res;
} void DFS(TreeNode* root,int &res,int add){
if(root->left == NULL && root->right == NULL){
add = add* + root->val;
res += add;
return;
}
add = add* + root->val;
if(root->left != NULL){
DFS(root->left,res,add);
}
if(root->right != NULL){
DFS(root->right,res,add);
}
}
};

EZ

Leetcode 129的更多相关文章

  1. leetcode@ [129] Sum Root to Leaf Numbers (DFS)

    https://leetcode.com/problems/sum-root-to-leaf-numbers/ Given a binary tree containing digits from 0 ...

  2. [LeetCode] 129. Sum Root to Leaf Numbers 求根到叶节点数字之和

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  3. Java实现 LeetCode 129 求根到叶子节点数字之和

    129. 求根到叶子节点数字之和 给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字. 例如,从根到叶子节点路径 1->2->3 代表数字 12 ...

  4. leetcode 129. Sum Root to Leaf Numbers ----- java

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  5. Leetcode#129 Sum Root to Leaf Numbers

    原题地址 二叉树的遍历 代码: vector<int> path; int sumNumbers(TreeNode *root) { if (!root) ; ; path.push_ba ...

  6. [LeetCode] 129. Sum Root to Leaf Numbers 解题思路

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  7. [LeetCode] 129. Sum Root to Leaf Numbers_Medium tag: DFS

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  8. Java for LeetCode 129 Sum Root to Leaf Numbers

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  9. LeetCode 129. 求根到叶子节点数字之和(Sum Root to Leaf Numbers)

    题目描述 给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字. 例如,从根到叶子节点路径 1->2->3 代表数字 123. 计算从根到叶子节点 ...

随机推荐

  1. Mapreduce 历史服务 配置启动查看

    如果没有进行配置的话,那个History是不可以进行点击的,点击进去就会报错!所以需要进行配置一下 使用命令启动HistoryServer 就可以查看任务执行的进度了 命令: sbin/mr-jobh ...

  2. Neo4j 文档

    Graph Fundamentals 基础 Basic concepts to get you going. A graph database can store any kind of data u ...

  3. Python示例

    http request:put # 定义函数:refresh segement # curl -X PUT -s --user "****:*****" -H 'Content- ...

  4. 【译】第40节---EF6-命令监听

    原文:http://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx 本节,将学习 ...

  5. django 应用中获取访问者ip地址

    通常访问者的IP就在其中,所以我们可以用下列方法获取用户的真实IP: #X-Forwarded-For:简称XFF头,它代表客户端,也就是HTTP的请求端真实的IP,只有在通过了HTTP 代理或者负载 ...

  6. go 内嵌对象类型

    demo1 // Sample program to show how to embed a type into another type and // the relationship betwee ...

  7. CentOS6.5下搭建ftp服务器(三种认证模式:匿名用户、本地用户、虚拟用户)

    CentOS 6.5下搭建ftp服务器 vsftpd(very secure ftp daemon,非常安全的FTP守护进程)是一款运行在Linux操作系统上的FTP服务程序,不仅完全开源而且免费,此 ...

  8. Java——文件及目录File操作

    API file.listFiles(); //列出目录下所有文件及子目录fileList[i].isFile() //判断是否为文件 fileList[i].isDirectory() //判断是否 ...

  9. ssh REMOTE HOST IDENTIFICATION HAS CHANGED!

    连接到docker的时候,有时因为image重新buid过,就提示 It is also possible that a host key has just been changed. 不让连接. 解 ...

  10. Qt的QVariant类

    QStandardItemModel类中的函数 bool setData(const QModelIndex &index, const QVariant &value, int ro ...