zoukankan      html  css  js  c++  java
  • 【easy】257. Binary Tree Paths 二叉树找到所有路径

    http://blog.csdn.net/crazy1235/article/details/51474128

    花样做二叉树的题……居然还是不会么……

     

    /**
     * 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:
        void binaryTreePaths(vector<string>& result,TreeNode* root,string t)  
        {  
            if(!root->left&&!root->right)  
            {  
                 result.push_back(t);  
                 return;  
            }  
            if(root->left)  
                binaryTreePaths(result,root->left,t+"->"+to_string(root->left->val));  
            if(root->right)  
                binaryTreePaths(result,root->right,t+"->"+to_string(root->right->val));      
                  
        }  
      
        vector<string> binaryTreePaths(TreeNode* root) {  
            vector<string> result;  
            if(root==NULL) return result;  
              
            binaryTreePaths(result,root,to_string(root->val));  
              
            return result;  
              
              
        }  
    };
  • 相关阅读:
    Java Concurrency
    Java Annotation,Java注解
    Think in java, notes
    嵌套事务
    java dynamic proxy,动态代理
    埃里克·雷蒙德
    HDU1222 Wolf and Rabbit
    HUT1098 素MM
    HDU1568 Fibonacci
    HDU1501 Zipper DFS+记忆化搜索
  • 原文地址:https://www.cnblogs.com/sherry-yang/p/8445981.html
Copyright © 2011-2022 走看看