leetcode Binary Tree Paths
来源:互联网 发布:vip视频盒子app源码 编辑:程序博客网 时间:2024/06/05 23:42
原题链接:https://leetcode.com/problems/binary-tree-paths/
Description
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:
/** * 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) { ans.clear(); if (!root) return ans; dfs(root, ""); return ans; }private: vector<string> ans; void dfs(TreeNode *x, string ret) { if (!x) return; if (!x->left && !x->right) { ans.push_back(ret + to_string(x->val)); return; } dfs(x->left, ret + to_string(x->val) + "->"); dfs(x->right, ret + to_string(x->val) + "->"); }};
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 第三方库冲突的处理
- VB/VC/易语言/Delphi 破解常见思路
- 剑指offer10 矩形覆盖
- mongodb3.0.6的下载和安装
- 加密与解密(修改关键数据实现中端破解)
- leetcode Binary Tree Paths
- 加密与解密(针对VB程序特性的破解)
- BZOJ2339: [HNOI2011]卡农
- 加密与解密(逆向过程中的Delphi特色)
- 简单演示BLOCK的基本使用方法
- eclipse中导入opencv
- POJ 3264 Balanced Lineup 【RMQ裸题 】
- 加密与解密(进阶!通过API寻找切入点)
- Myeclipse 2015 stable 2.0 完美破解方法