public class Solution
{
private Stack<string> ST = new Stack<string>();
private string SmallestStr = String.Empty;
private string[] Ary = new string[] { "a","b","c","d","e","f","g",
"h","i","j","k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"};
private void SearchTree(TreeNode root)
{
if(root!=null)
{
var index = root.val;
var str = Ary[index];
ST.Push(str); if(root.left!=null)
{
SearchTree(root.left);
} if(root.right!=null)
{
SearchTree(root.right);
}
if(root.left==null && root.right==null)
{
//find a leaf node
var a1 = ST.ToArray();
StringBuilder sb1 = new StringBuilder();
for (int i = ; i < a1.Length;i++)
{
sb1.Append(a1[i]);
}
if(string.IsNullOrEmpty(SmallestStr) ||
string.Compare(SmallestStr, sb1.ToString()) >
)
{
SmallestStr = sb1.ToString();
}
}
ST.Pop();
}
} public string SmallestFromLeaf(TreeNode root)
{
SearchTree(root);
return SmallestStr;
}
}

leetcode988的更多相关文章

  1. [Swift]LeetCode988. 从叶结点开始的最小字符串 | Smallest String Starting From Leaf

    Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to  ...

随机推荐

  1. 引用 自动化测试基础篇--Selenium Python环境搭建

    原文链接:https://www.cnblogs.com/sanzangTst/p/7452922.html 鸣谢参藏法师. 学习selenium python需要的工具: 1.浏览器 2.Pytho ...

  2. C++进阶--理解左值和右值

    /* * 理解左值和右值 * * * 为什么要关心这个? * 1. 有助于理解C++结构,搞明白编译器的错误和警告 * 2. C++ 11中引入了右值引用,理解左值右值是前提 * */ /* * 简单 ...

  3. bzoj4980: 第一题

    Description 神犇xzyo听说sl很弱,于是出了一题来虐一虐sl.一个长度为2n(可能有前缀0)的非负整数x是good的,当且仅当 存在两个长度为n(可能有前缀0)的非负整数a.b满足a+b ...

  4. Ubuntn16.04.3配置root权限及启用root用户

    景 如果你是测试环境需要在VM中装了Ubuntn,安装完成后会创建一个Ubuntn的默认用户,默认用户因为权限的问题很多系统的配置文件不可以打开,默认是只读状态. 那么可以通过以下两种方式切换到roo ...

  5. C与C++的部分区别

    1.函数无形参情况 void test() { } int main() { test(,); ; } 在C语言中形参括号没有参数时代表接受任意多的参数,而在C++语言中代表void(无参数) 所以上 ...

  6. Java学习——Applet菜单

    程序功能:在窗口中添加菜单栏,在菜单栏添加菜单项,并添加下拉菜单和 2 级菜单,通过选择菜单项可以执行不同操作,生成如下图所示窗口. package cys; import java.awt.*; i ...

  7. Oracle下PLSQL连接没有数据库的问题

    https://blog.csdn.net/master_yao/article/details/51055850 参考博文地址 当PLSQL连接提示时请注意 请将首选项里内容进行修改 指定oci.d ...

  8. Zabbix 创建监控项目

    #1 #2 [root@nod01 zabbix_agentd.d]# pwd/etc/zabbix/zabbix_agentd.d 新建文件nod.conf [root@nod01 zabbix_a ...

  9. PostgreSQL中的group by

    问题描述:今天使用了PostgerSQL查询统计一下相关信息,发现 报错了 SELECT * FROM "public"."dc_event_data" WHE ...

  10. Error detected while processing function pythoncomplete#Complete: 错误解决

    python vim 环境配置好后,莫名奇妙总是出现:Error detected while processing function pythoncomplete#Complete: 恼人的错误,多 ...