【easy】257. Binary Tree Paths 二叉树找到所有路径
生活随笔
收集整理的這篇文章主要介紹了
【easy】257. Binary Tree Paths 二叉树找到所有路径
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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; } };?
轉(zhuǎn)載于:https://www.cnblogs.com/sherry-yang/p/8445981.html
總結(jié)
以上是生活随笔為你收集整理的【easy】257. Binary Tree Paths 二叉树找到所有路径的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷P3195 [HNOI2008]玩具
- 下一篇: [leetcode]203. Remov