public class Solution
{
List<int> list = new List<int>(); private void postTree(TreeNode root)
{
if (root != null)
{
list.Add(root.val);
if (root.left != null)
{
postTree(root.left);
}
if (root.right != null)
{
postTree(root.right);
}
}
} public bool IsUnivalTree(TreeNode root)
{
postTree(root);
var count = list.GroupBy(x => x).Count();
if (count == )
{
return true;
}
return false;
}
}

leetcode965的更多相关文章

  1. [Swift]LeetCode965. 单值二叉树 | Univalued Binary Tree

    A binary tree is univalued if every node in the tree has the same value. Return true if and only if ...

  2. Leetcode965. Univalued Binary Tree单值二叉树

    如果二叉树每个节点都具有相同的值,那么该二叉树就是单值二叉树. 只有给定的树是单值二叉树时,才返回 true:否则返回 false. 示例 1: 输入:[1,1,1,1,1,null,1] 输出:tr ...

  3. LeetCode965. 单值二叉树

    题目 1 class Solution { 2 public: 3 int flag = 0; 4 bool isUnivalTree(TreeNode* root){ 5 isUnivalTree1 ...

随机推荐

  1. $.grep()的用法

    grep()方法用于数组元素过滤筛选 grep(array,callback,invert) array:待过滤数组; callback:处理数组中的每个元素,并过滤元素,该函数中包含两个参数,第一个 ...

  2. 直接new一个对象出来

  3. leetcode:Maximum Depth of Binary Tree【Python版】

    # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...

  4. RabbitMQ消息可靠性分析

    消息中间件的可靠性是指对消息不丢失的保障程度:而消息中间件的可用性是指无故障运行的时间百分比,通常用几个 9 来衡量.不存在绝对的可靠性只能尽量趋向完美.并且通常可靠性也意味着影响性能和付出更大的成本 ...

  5. oracle之 redo过高诊断

    一.诊断过度redo 要找到生成大量重做的会话,您可以使用以下任何一种方法.这两种方法都检查生成的撤销量.当一个事务生成撤销,它将自动生成重做. 当需要检查生成大量的程序时,使用第一个查询.当这些程序 ...

  6. JUC集合之 ConcurrentSkipListMap

    ConcurrentSkipListMap介绍 ConcurrentSkipListMap是线程安全的有序的哈希表,适用于高并发的场景. ConcurrentSkipListMap和TreeMap,它 ...

  7. CommonsChunkPlugin知识点

    CommonsChunkPlugin 的作用就是提取代码中的公共模块,然后将公共模块打包到一个独立的文件中去,以便在其它的入口和模块中使用. 多个 html共用一个js文件(chunk),可用Comm ...

  8. asp.net如何使用cookie(创建、保存、读取)

    Cookie的用法也和ASP中差不多.比如我们建立一个名为aspcn,值为大众的cookie HttpCookie cookie = new HttpCookie("aspcn") ...

  9. RFID:ISO14443、15693、18000体系分析

    射频标签的通信标准是标签芯片设计的依据,目前国际上与RFID相关的通信标准主要有:ISO/IEC 18000标准(包括7个部分,涉及125KHz, 13.56MHz, 433MHz, 860-960M ...

  10. TextBox(只允许输入字母或者数字)——重写控件

    实现如下: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System ...