257. Binary Tree Paths
来源:互联网 发布:孕婴店网络宣传广告语 编辑:程序博客网 时间:2024/06/05 22:31
/** * 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 { void binaryTree(TreeNode *root,vector<int> &cur,vector<vector<int>> &ret) { if(root) { cur.push_back(root->val); if(root->left) binaryTree(root->left,cur,ret); if(root->right) binaryTree(root->right,cur,ret); if(root->left==NULL&&root->right==NULL) ret.push_back(cur); cur.pop_back(); } }public: vector<string> binaryTreePaths(TreeNode* root) { vector<int> curi; vector<vector<int>> reti; vector<string> ret; binaryTree(root,curi,reti); for(int i=0;i<reti.size();i++) { string temp; for(int j=0;j<reti[i].size();j++) { if(j<reti[i].size()-1) { temp=temp+to_string(reti[i][j])+"->"; } else { temp=temp+to_string(reti[i][j]); } } ret.push_back(temp); } return ret; }};
0 0
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- leetcode 278: First Bad Version
- Extjs Window用法详解
- 个人总结
- IOS常用正则表达式
- 数据结构之队列【java实现】
- 257. Binary Tree Paths
- Android窃听用户发出的短信
- Netsniff-NG
- Android APP架构设计——MVC、MVP和MVVM介绍
- ubuntu配置samba
- 12.6static类成员
- 单例模式
- Codeforces 92A-Chips
- Android学习笔记