[LeetCode]Binary Tree Paths
来源:互联网 发布:linux中cd的用法 编辑:程序博客网 时间:2024/06/08 08:20
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> ret; string temp ; traversal(ret,temp,root); return ret; } void traversal(vector<string> &ret,string temp,TreeNode *root){ if(root==nullptr) return ; temp += ("->"+ to_string(root->val)); traversal(ret,temp,root->left); traversal(ret,temp,root->right); if(root->left==nullptr&&root->right==nullptr) ret.push_back(temp.substr(2)); }};
0 0
- Leetcode: Binary Tree Paths
- [LeetCode] Binary Tree Paths
- [Leetcode]Binary Tree Paths
- leetcode:Binary Tree Paths
- [leetcode] Binary Tree Paths
- Leetcode: Binary Tree Paths
- LeetCode:Binary Tree Paths
- leetcode Binary Tree Paths
- leetcode Binary Tree Paths
- LeetCode:Binary Tree Paths
- LeetCode Binary Tree Paths
- LeetCode Binary Tree Paths
- LeetCode Binary Tree Paths
- LeetCode || Binary Tree Paths
- *LeetCode-Binary Tree Paths
- Binary Tree Paths -- leetcode
- LeetCode---Binary Tree Paths
- leetcode-Binary Tree Paths
- IOS删除沙盒所有同类型的文件
- 你真的会写单例模式吗——Java实现
- 如何为Swift进行宏定义
- 如何根据树的两个遍历顺序确定另外一个遍历顺序
- git commit 撤销
- [LeetCode]Binary Tree Paths
- MySQL左连接、右连接、笛卡尔积的表现形式
- 数据存储----------------SDcard
- python 模拟登陆leetcode
- uoj171 bzoj 4405: [wc2016]挑战NPC 一般图最大匹配
- Uva 11426 - GCD - Extreme (II) 欧拉函数
- java中的stack
- datagrid页面获取表单一条数据的例子
- Android学习之ItemTouchHelper实现RecylerView的拖拽以及滑动删除功能