17 Mar 2023ErlangUnknown

Root Equals Sum Of Children

notes and solution files for root equals sum of children.

this entry collects the solution files i have for root equals sum of children. i may expand it with a fuller write-up later, but the implementation files are already here.

available solution files

  • Erlang root-equals-sum-of-children/solution.erl

Solution files

Erlangroot-equals-sum-of-children/solution.erl
%% Definition for a binary tree node.
%%
%% -record(tree_node, {val = 0 :: integer(),
%%                     left = null  :: 'null' | "syntax-comment">#tree_node{},
%%                     right = null :: 'null' | "syntax-comment">#tree_node{}}).

-spec check_tree(Root :: "syntax-comment">#tree_node{} | null) -> boolean().
check_tree("syntax-comment">#tree_node{val = RootVal, left = #tree_node{val = LeftVal}, right = #tree_node{val = RightVal}}) ->
    RootVal =:= LeftVal + RightVal.