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 ...
随机推荐
- 两台linux完美实现双机热备【来源网络尚未实践】
[来源:http://rainbird.blog.51cto.com/211214/225541/] 一直想做基于linux的双机热备,一直没有时间和机会.一直以为只要做双机热备的实验就必 ...
- Java并发--如何创建线程
下面是本文的目录大纲: 一.Java中关于应用程序和进程相关的概念 二.Java中如何创建线程 三.Java中如何创建进程 转载原文链接:http://www.cnblogs.com/dolphin0 ...
- bzoj 4570 妖怪
bzoj 4570 妖怪 正解应该是 \(O(nlogn)\) 的凸包,但被我的 \(O(100n)\) 的三分水过去了. 记 $x=\frac b a $ ,显然有 \(strength_i=ATK ...
- 《DSP using MATLAB》示例 Example 6.25
代码: % x = [-0.9, 0.81]; [y, L, B] = QCoeff(x, 3) % Unquantized parameters r = 0.9; theta = pi/3; a1 ...
- FileZilla Server配置
1.在服务器上安装并配置服务端: 安装过程这里不再赘述,一直下一步,在跳出弹窗时勾选“Always connect to this server”,然后点击“Connect”即可(密码可自行设置) 之 ...
- HDU4864 Task
题意 Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, t ...
- 收藏一下mybatis全局参数配置
http://blog.csdn.net/shaoduo/article/details/54285981
- 使用 Excel 可以很方便的做程序原型
使用 Excel 可以很方便的做程序原型 比如计算 单片机的端口模式,可以使用 Excel 很方便的计算出来,花了 15 分钟做好. 还可以使用函数自动根据二进制计算出 十六进制. 然后如果再使用软件 ...
- oracle之 利用 controlfile trace文件重建控制文件
一. 11g RAC 重建控制文件 1. --"create controlfile"命令生成到追踪文件中:alter database backup controlfile to ...
- bzoj 1927 [Sdoi2010]星际竞速——网络流
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1927 每个点拆点保证只经过一次. 主要是如果经过了这个点,这个点应该向汇点流过去表示经过了它 ...