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 ...
随机推荐
- JVM原理三-----GC模块,垃圾回收
GC方法:在JVM启动时填入参数(比如:-XX:+UseConcMarkSweepGC ) 算法区分: 1.古老回收算法: Reference Counting ,对象有一个引用,即增加一个计数,删 ...
- 深度优先搜索入门:POJ1164城堡问题(递归、用栈模拟递归)
将问题的各状态之间的转移关系描述为一个图,则深度优先搜索遍历整个图的框架为:Dfs(v) {if( v 访问过)return;将v标记为访问过;对和v相邻的每个点u: Dfs(u);}int main ...
- hiho1602本质不同的回文子串的数量
给定一个字符串S,请统计S的所有子串中,有多少个本质不同的回文字符串? 注意如果两个位置不同的子串满足长度相同且对应字符也都相同,则认为这两个子串本质上是相同的. Input 一个只包含小写字母的字符 ...
- 报错 Inferred type 'S' for type parameter 'S' is not within its bound; 解决办法
出现情况: Inferred type 'S' for type parameter 'S' is not within its bound; should extends xxxxxx 出现这种问题 ...
- Paths中的几个重要元素
Paths中的几个重要元素 Points void CGContextMoveToPoint ( CGContextRef c, CGFloat x, CGFloat y ); 指定 ...
- BZOJ4145 [AMPPZ2014]The Prices
题意 你要购买m种物品各一件,一共有n家商店,你到第i家商店的路费为d[i],在第i家商店购买第j种物品的费用为c[i][j],求最小总费用. \(n \leq 100,m \leq 16\) 分析 ...
- gradle multiproject && docker build
备注: 环境准备 : docker , gradle(使用wrapper,或者全局安装),测试环境使用mac 1. gradle 安装 brew install gradle 2. docke ...
- lapis 处理接收到的json 数据
备注: 在restful api 开发过程中,大家一般使用的都是json 格式的数据lapis 在处理json 数据上也是比较方便的 1. 使用的api 说明 local ...
- mui.fire 目标页无法监听到 触发事件
//获得详情页面 if(!detailPage){ detailPage = plus.webview.getWebviewById('detail.html'); } //触发详情页面的newsId ...
- SpringBoot 接收 单个String入参之解决方案
场景: 在做接口时,有的时候,接口入参只需要一个参数,如果将一个参数封装成一个对象很麻烦,故有了以下方式: 思路: spring自带的参数解析器貌似是不具备这个能力的,所有自定义 方式方法: 1.定义 ...