• functionclass[LeetCode]Path Sum II


    在本篇文章中,我们主要介绍functionclass的内容,自我感觉有个不错的建议和大家分享下

        每日一道理
    只有启程,才会到达理想和目的地,只有拼搏,才会获得辉煌的成功,只有播种,才会有收获。只有追求,才会品味堂堂正正的人。
    struct TreeNode {
    	int val;
    	TreeNode *left;
    	TreeNode *right;
    	TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    };
    
    class Solution {
    //record all the path, though dfs is not time efficient bu also work at most time	
    public:
    	void DFS(TreeNode* root, int curSum, vector<int> curPath, vector<vector<int>>& ansPath, int sum)
    	{
    		if(!root)
    			return;
    		curSum += root->val;
    		curPath.push_back(root->val);
    		if(!root->left && !root->right)
    		{
    			if(curSum == sum)
    				ansPath.push_back(curPath);
    			return;
    		}
    		DFS(root->left, curSum, curPath, ansPath, sum);
    		DFS(root->right, curSum, curPath, ansPath, sum);
    	}
        vector<vector<int> > pathSum(TreeNode *root, int sum) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            vector<vector<int> > ansPath;
    		vector<int> curPath;
    		DFS(root, 0, curPath, ansPath, sum);
    		return ansPath;
        }
    };

    文章结束给大家分享下程序员的一些笑话语录: 手机终究会变成PC,所以ip会比wm更加畅销,但是有一天手机强大到一定程度了就会发现只有wm的支持才能完美享受。就好比树和草,草长得再高也是草,时间到了条件成熟了树就会窜天高了。www.ishuo.cn

    --------------------------------- 原创文章 By
    function和class
    ---------------------------------

  • 相关阅读:
    SpringBoot进阶教程(六十二)整合Kafka
    98每日博客
    96每日博客
    95日每周总结
    829每周总结
    815每周总结
    81每周总结
    822每周总结
    97每日博客
    88每周总结
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3111532.html
Copyright © 2020-2023  润新知