6 kyu

Sum The Tree

2,257 of 4,921jz9000

Description:

Given a node object representing a binary tree:

Node:
  value: <int>,
  left: <Node> or null,
  right: <Node> or null
Node:
  value: <int>,
  left: <Node> or null,
  right: <Node> or null
struct node
{
  int value;
  node* left;
  node* right;
}
public class Node
{  
    public int Value;  
    public Node Left;  
    public Node Right;
    
    public Node(int value, Node left = null, Node right = null)
    {
      Value = value;
      Left = left;
      Right = right;
    }
}  

write a function that returns the sum of all values, including the root. Absence of a node will be indicated with a null value.

Examples:

10
| \
1  2
=> 13

1
| \
0  0
    \
     2
=> 3
Trees
Recursion
Binary Trees
Binary Search Trees
Data Structures
Fundamentals

Stats:

CreatedOct 14, 2016
PublishedOct 14, 2016
Warriors Trained9717
Total Skips2100
Total Code Submissions15516
Total Times Completed4921
JavaScript Completions2257
C++ Completions1448
C Completions933
C# Completions438
Total Stars186
% of votes with a positive feedback rating90% of 781
Total "Very Satisfied" Votes646
Total "Somewhat Satisfied" Votes119
Total "Not Satisfied" Votes16
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • jz9000 Avatar
  • jhoffner Avatar
  • user5036852 Avatar
  • comet Avatar
  • Varveyn Avatar
  • Voile Avatar
  • Souzooka Avatar
  • FArekkusu Avatar
  • Awesome A.D. Avatar
Ad