LeetCode[257] Binary Tree Paths
来源:互联网 发布:linux ftp 防火墙设置 编辑:程序博客网 时间:2024/06/11 17:37
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
1 / \2 3 \ 5
All root-to-leaf paths are:
["1->2->5", "1->3"]
/** * 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:vector<string> binaryTreePaths(TreeNode* root) {vector<string> result;if (root == NULL)return result;Solution::PathString(result, root, to_string(root->val));return result;}void PathString(vector<string>& result, TreeNode* pNode, string path){if (pNode->left == NULL && pNode->right == NULL)result.push_back(path);if (pNode->left)PathString(result, pNode->left, path + "->" + to_string(pNode->left->val));if (pNode->right)PathString(result, pNode->right, path + "->" + to_string(pNode->right->val));}};
0 0
- leetcode 257: Binary Tree Paths
- leetCode #257 Binary Tree Paths
- LeetCode(257)Binary Tree Paths
- [leetcode 257]Binary Tree Paths
- leetcode[257] Binary Tree Paths
- LeetCode 257: Binary Tree Paths
- leetcode 257 : Binary Tree Paths
- 【LEETCODE】257-Binary Tree Paths
- [leetcode 257] Binary Tree Paths
- LeetCode 257 Binary Tree Paths
- LeetCode 257:Binary Tree Paths
- LeetCode 257:Binary Tree Paths
- leetcode 257:Binary Tree Paths
- leetcode-257-Binary Tree Paths
- LeetCode 257Binary Tree Paths
- LeetCode 257 Binary Tree Paths
- leetcode 257 Binary Tree Paths
- LeetCode-257:Binary Tree Paths
- linux下能上内网但是上不了外网的解决
- Bean的作用域及生命周期
- 计算机的组成及作用
- 在CentOS6.4中更新安装FireFox浏览器最新版
- 让我们彻底搞懂C/C++函数指针吧(二)
- LeetCode[257] Binary Tree Paths
- 高精度之加法模板
- 【LeetCode-144】Binary Tree Preorder Traversal(C++)
- java.计算电费
- 短信验证集成步骤
- 网络访问 URL,HttpURLConnection及 HttpClient:
- JAVA 第十四章 带参数的方法
- jdk,jre与jvm的区别?IDE是什么?
- iOS--webView的使用相关