Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

uni valued tree

    public static int CountUnivalSubtrees(Node node) 
    {
        if (node == null)
            return 0;

        int count = CountUnivalSubtrees(node.left);
        count += CountUnivalSubtrees(node.right);

        return IsUnivalTree(node) ? count + 1 : count;
    }

    private static bool IsUnivalTree(Node node) 
    {
        if (node == null)
            return true;
        if (node.left != null && node.left.val != node.val)
            return false;
        if (node.right != null && node.right.val != node.val)
            return false;
        return IsUnivalTree(node.left) && IsUnivalTree(node.right);
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to know what object player touches unity 2D 
Csharp :: clear array c# 
Csharp :: unity detect if animation is playing 
Csharp :: game object find 
Csharp :: Generate UUID in c# 
Csharp :: fair division 
Csharp :: C# .net core convert int to enum 
Csharp :: unity c# check if multiple keys are pressed 
Csharp :: how to make int to text unity 
Csharp :: c# list get element from end 
Csharp :: move object to mouse unity 
Csharp :: rotation facing mouse unity 
Csharp :: unity access phone camera 
Csharp :: set particle system start colour + random between two 
Csharp :: c# convert string to enum value 
Csharp :: c# get pixel color from image 
Csharp :: linq where list contains another list 
Csharp :: c# datagridview change column name 
Csharp :: unity 2d joystick controls 
Csharp :: bootstrap modal 
Csharp :: c# unity get lines 
Csharp :: c# convert string to int 
Csharp :: c# relative path to project folder 
Csharp :: generate random name c# 
Csharp :: C# How to write Hello World 
Csharp :: open folder dialog c# 
Csharp :: c# inline if 
Csharp :: prevent page refresh 
Csharp :: c# get set value 
Csharp :: dotnet new project 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =