257. Binary Tree Paths
来源:互联网 发布:h5 js 跳转到原生界面 编辑:程序博客网 时间:2024/05/22 15:10
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) {if (root == NULL){return res;}vector<int> path;helper(root, path);return res;}private:void helper(TreeNode* root, vector<int>& path){path.push_back(root->val);if (root->left == NULL&&root->right == NULL){string p;int len = path.size();for (int i = 0; i < len; i++){if (i != len - 1){p += to_string(path[i]);p += "->";}else{p += to_string(path[i]);}}res.push_back(p);}if (root->left){helper(root->left, path);}if (root->right){helper(root->right, path);}path.pop_back();}vector<string> res;};
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
- 若不自律,则注定一无所成。
- 时下流行devops关键词:分布式架构、一体化架构和微服务架构
- 全国低于30ms响应速度:千万级魅族用户的异地多点网络
- 关于android,so库那点事~~
- Android 图片缓存处理
- 257. Binary Tree Paths
- pod里的框架不是最新的(比github里面的版本低)
- Error when passing date to create solr date format.java.text.ParseException: Unparseable date: "Wed
- 验证是否是数字的正则
- 使用U盘安装windows系统时提示找不到任何设备驱动程序
- Android系统Recovery工作原理之使用update.zip升级过程分析(六)---Recovery服务流程细节
- iOS Storyboards Container View Controller整理笔记
- openstack图库
- asp.net mvc EF修改指定数据库列的数据