leetcode671】的更多相关文章

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes.…
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 findSeco…
给定一个非空特殊的二叉树,每个节点都是正数,并且每个节点的子节点数量只能为 2 或 0.如果一个节点有两个子节点的话,那么这个节点的值不大于它的子节点的值. 给出这样的一个二叉树,你需要输出所有节点中的第二小的值.如果第二小的值不存在的话,输出 -1 . 题目应该少说了树的节点值都是大于等于0的 class Solution { public: int findSecondMinimumValue(TreeNode* root) { if(root == NULL) return -1; int…
题目 纯暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 int findSecondMinimumValue(TreeNode* root) { 5 dfs(root); 6 sort(ans.begin(),ans.end()); 7 int res = ans[0]; 8 for(int i = 1;i < ans.size();i++){ 9 if(ans[i] != res) return ans[i]; 10 } 11 r…