/**
* 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. Unity3D学习笔记(二十七):MVC框架下的背包系统(2)

    Tools FileTools using System.Collections; using System.Collections.Generic; using UnityEngine; using ...

  2. 1、Keepalived及VRRP原理介绍

    keepalived:即在linux中vrrp协议的实现 http://www.keepalived.org/ 什么是Keepalived?  Keepalived是一个用C语言编写的路由软件.该项目 ...

  3. hdu 2034 改革春风吹满地 多边形面积

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem ...

  4. spring boot Tomcat访问日志

    1.Tomcat设置访问日志 <Host name="localhost" appBase="webapps" unpackWARs="true ...

  5. CentOS7下搭建Nginx+PHP7的安装配置

    一.安装编译工具及库文件: yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 环境要求 nginx是C ...

  6. swfupload上传图片

    项目结构 以及插件需要的文件如图所示 前端代码: <!DOCTYPE html> <html> <head> <title>SWFUpload</ ...

  7. django自定义Admin actions

    通常情况下,admin的工作模式是“选中目标,然后修改目标”,但在同时修改大量目标的时候,这种模式就变得重复.繁琐. 为此,admin提供了自定义功能函数actions的手段,可以批量对数据进行修改. ...

  8. PostgreSQL 扩展开发基础教程

    搭建基础结构 安装扩展 sudo apt-get install postgresql-contribcreatedb stupsql stucreate extension pg_buffercac ...

  9. Python中数据类型

    一.整数 Python可以处理任意大小的整数,当然包括负整数,在Python程序中,整数的表示方法和数学上的写法一模一样,例如:1,100,-8080,0,等等. 计算机由于使用二进制,所以,有时候用 ...

  10. chkconfig命令参数

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...