leetcode988
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的更多相关文章
- [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 ...
随机推荐
- Maven的classifier作用
classifier可以是任意的字符串,用于拼接在GAV之后来确定指定的文件. 可用于区分不同jdk版本所生成的jar包 <dependency> <groupId>net.s ...
- [UE4]使用C++重写蓝图,SpawnObject根据类型动态创建UObject
先大量使用蓝图制作项目,后续再用C++把复杂的蓝图重写一遍,用C++代码按照蓝图依葫芦画瓢就可以了,很简单,但需要遵守一些原则: 第一种方法:使用继承 一.创建一个C++类作为蓝图的父类(C++类继承 ...
- [UE4]使用DataTable
- Linux 防火墙和SELinux的开启和关闭
防火墙(firewalld) 临时关闭防火墙 systemctl stop firewalld 永久防火墙开机自关闭 systemctl disable firewalld 临时打开防火墙 syste ...
- Replicating a 2D dynamic array
转自:https://forums.unrealengine.com/community/community-content-tools-and-tutorials/105-saxonrahs-tut ...
- UE4 几个好用的插件和Wiki教程
转自:http://blog.csdn.net/u014532636/article/details/72729881 https://github.com/ue4plugins/LoadingScr ...
- 第5章 IP地址和子网划分(3)_子网划分
6.子网划分 6.1 地址浪费 (1)IPv4公网地址资源日益紧张,为减少浪费,使IP地址能够充分利用,就要用到子网划分技术. (2)传统上一个C类地址,如212.2.3.0/24,其可用的地址范围为 ...
- java类加载器 Bootstrap、ExtClassLoader、AppClassLoader的关系
1.Bootstrap. ExtClassLoader. AppClassLoader是java最根正苗红的类加载器.2.Bootstrap是本地代码编写的(例如C), ExtClassLoader. ...
- 干货 | 100+个NLP数据集大放送,再不愁数据!
奉上100多个按字母顺序排列的开源自然语言处理文本数据集列表(原始未结构化的文本数据),快去按图索骥下载数据自己研究吧! 数据集 Apache软件基金会公开邮件档案:截止到2011年7月11日全部公开 ...
- ELK+zookeeper+kafka+rsyslog集群搭建
前言 环境困境: 1.开发人员无法登陆服务器 2.各系统都有日志,日志数据分散难以查找 3.日志数据量大,查询忙,不能实时 环境要求: 1.日志需要标准化 集群流程图: 角色: 软件: 以 ...