Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1represents 'b', and so on.

Find the lexicographically smallest string that starts at a leaf of this tree and ends at the root.

(As a reminder, any shorter prefix of a string is lexicographically smaller: for example, "ab" is lexicographically smaller than "aba".  A leaf of a node is a node that has no children.)

Runtime: 4 ms, faster than 100.00% of C++ online submissions for Smallest String Starting From Leaf.
Memory Usage: 884.7 KB, less than 100.00% of C++ online submissions for Smallest String Starting From Leaf.
class Solution {
public:
string smallestFromLeaf(TreeNode* root) {
vector<string> a;
helper(root, a, "");
sort(a.begin(), a.end());
return a[];
}
void helper(TreeNode* root, vector<string>& a, string parent){
if(!root) return;
string tmpc(,(char)('a'+root->val));
string tmps = tmpc + parent;
if(!root->left && !root->right){
a.push_back(tmps);
return;
}
helper(root->left, a, tmps);
helper(root->right, a, tmps);
}
};

最新文章

  1. JavaScript中尺寸、坐标
  2. jquery 触发/失去焦点事件例子详解
  3. python 实现简单排序
  4. sqlplus链接数据库报ORA-09925: Unable to create audit trail file
  5. android mvvm
  6. [ShortCut] Visual Studio快捷键
  7. Lighttpd
  8. 【转载】kafka的工作原理
  9. iptables使用
  10. Codeforces Round #337 Vika and Segments
  11. Android下结束进程的方法
  12. 【转】adb shell dumpsys 命令
  13. oracle填坑之PLSQL中文显示为问号
  14. Java 8 新特性-菜鸟教程 (0) -Java 8 新特性
  15. 关于GPL协议的理解(开源与商用、免费与收费的理解)
  16. linux内核分析 第5章读书笔记
  17. oracle client字符集设置 乱码问题
  18. Python学习笔记020——数据库中的数据类型
  19. Oracle数据库学习(二):Oracle Linux下oracle、ogg的挂载与参数配置
  20. Kail安装后的配置

热门文章

  1. 2.Buffer 缓冲区
  2. Scyther攻击输出图的解释(之二)
  3. 切换composer国内镜像 Laravel China停用,切换阿里云composer全量镜像
  4. rabbitMQ安装 [linux]
  5. 学习笔记:Python序列化常用工具及性能对比
  6. flink相关
  7. [ 原创 ] Map之HashMap的使用方法
  8. spring-mybatis+spring整合
  9. proc文件系统详解
  10. 聊聊我理解的ANSI C、ISO C、GNU C、POSIX C