zoukankan      html  css  js  c++  java
  • 路径总和--leetcode112

     方法1:递归

     
    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     struct TreeNode *left;
     *     struct TreeNode *right;
     * };
     */


    bool hasPathSum(struct TreeNode* root, int sum){
        if(root==NULL)
        {
            return false;
        }
        if(root->left==NULL&&root->right==NULL)
        {
            return sum==root->val;
        }
        return hasPathSum(root->left,sum-root->val)||hasPathSum(root->right,sum-root->val);
    }
  • 相关阅读:
    缓存Cache
    RDD的行动操作
    redis数据库的配置
    requests的封装(user-agent,proxies)
    phantjs
    python多线程
    etree-xpath
    Flask
    Flask
    Flask
  • 原文地址:https://www.cnblogs.com/sbb-first-blog/p/13258872.html
Copyright © 2011-2022 走看看