leetcode671
class Solution {
public:
vector<int> V; void postTree(TreeNode* node)
{
if (node != NULL)
{
V.push_back(node->val);
if (node->left != NULL)
{
postTree(node->left);
}
if (node->right != NULL)
{
postTree(node->right);
}
}
} int findSecondMinimumValue(TreeNode* root) {
postTree(root);
int result = -;
if (V.size() < )
{
return -;
}
sort(V.begin(), V.end());
for (auto v : V)
{
cout << v << " ";
}
cout << endl;
for (int i = ; i < V.size(); i++)
{
if (V[i - ] == V[i])
{
continue;
}
else
{
result = V[i];
break;
}
}
return result;
}
};
leetcode671的更多相关文章
- [Swift]LeetCode671. 二叉树中第二小的节点 | Second Minimum Node In a Binary Tree
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...
- Leetcode671.Second Minimum Node In a Binary Tree二叉树中的第二小结点
给定一个非空特殊的二叉树,每个节点都是正数,并且每个节点的子节点数量只能为 2 或 0.如果一个节点有两个子节点的话,那么这个节点的值不大于它的子节点的值. 给出这样的一个二叉树,你需要输出所有节点中 ...
- LeetCode671. 二叉树中第二小的节点
题目 纯暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 int findSecondMinimumValue(TreeNode* r ...
随机推荐
- Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
- hiredis处理zscan和hscan的reply
zscan的返回值可以看做是一个二维数组,第一维包含两个元素:string类型的游标cursor和集合元素数组:第二维即集合元素数组,这个数组交替存放着集合元素和score,元素和score也都是st ...
- MYSQL 调优和使用必读
转载自:http://blog.eood.cn/mysql#rd?sukey=fc78a68049a14bb29c60f21c5254b15a1a9234459cf25ff467de14129ca11 ...
- 对Json的各种遍历方法
慎用for in函数(有可能由于原型链的问题导致遍历问题): 如果要是用for in 一定要使用if (obj1.hasOwnProperty(key)) {}先做判断 解决方法 :1.eval() ...
- svn 操作命令
1.第一次提交代码到svn svn import project_directory PATH 2.将文件checkout到本地svn checkout path(path是服务器上的目录) 例如:s ...
- Protel 99 铺铜的一个坑 Pour Over Same
Protel 99 铺铜的一个坑 Pour Over Same 好久没用 Protel 99 了,修改了一个旧的 PCB 文件. 需要修改线路,由于改了线路需要重新铺铜,得重新画铺铜的边框. 以下这个 ...
- git忽略已经提交的文件【转载】
有时候我们添加.gitignore文件之前已经提交过了文件..gitignore只能忽略那些原来没有被track的文件(自添加以后,从未 add 及 commit 过的文件),如果某些文件已经被纳入了 ...
- 记一笔vue中的中央事件总线的问题,以及解决方案
代码结构:首先HeaderNav组件是被单独拎出来的,router-view中就对应了内容组件,由于有时候i有的界面的header内容是不一样的,因此要用到兄弟组件的相互通信,这个时候我首先选择了bu ...
- 树的遍历——pat1043
http://pat.zju.edu.cn/contests/pat-a-practise/1043 给予N个数字组成二叉搜索树,判断这个数列是否由先序遍历得出或是镜像先序遍历得出,若是则输出相应的后 ...
- Unit03: Spring Web MVC简介 、 基于XML配置的MVC应用 、 基于注解配置的MVC应用
Unit03: Spring Web MVC简介 . 基于XML配置的MVC应用 . 基于注解配置的MVC应用 springmvc (1)springmvc是什么? 是一个mvc框架,用来简化基于mv ...