LeetCode(257)Binary Tree Paths
来源:互联网 发布:mac键盘灯不亮 编辑:程序博客网 时间:2024/05/22 17:22
c++代码如下
/** * 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 tra(TreeNode *root, string &path, vector<string> &result) { if(root->left == NULL && root->right == NULL) { string tmp = path; path += to_string(root->val); result.push_back(path); path = tmp; return; } string tmp = path; path = path + to_string(root->val); path += "->"; if(root->left) tra(root->left, path, result); if(root->right) tra(root->right, path, result); path = tmp; } vector<string> binaryTreePaths(TreeNode* root) { vector<string> result; string path; if(root == NULL) return result; tra(root, path, result); return result; }};
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
- CF 316 E. Pig and Palindromes 求左上角走到右下角是回文的方法数 DP
- android 两次点击back键退出程序
- Block方法与Block属性结合使用的小实现
- 移植lame-3.99.5库
- uva 11401 Triangle Counting 数三角形 (计数问题)
- LeetCode(257)Binary Tree Paths
- 字符设备控制
- win7自带IE浏览器图标如何删除
- 利用jquery完成表单域的收集,利用ajax实现信息传递给服务器存储
- Android系列之Fragment(二)----Fragment的生命周期和返回栈
- Hadoop参数文件
- C#接口作用的深入理解
- cocos2d-js 翻版神棍传说demo
- COCOS2dx 3.5 实现带白色边框圆形头像功能