Skip to content

Files

Latest commit

author
Mauricio Klein
Dec 30, 2019
1a574a7 · Dec 30, 2019

History

History
24 lines (16 loc) · 440 Bytes

README.md

File metadata and controls

24 lines (16 loc) · 440 Bytes

Arithmetic Binary Tree

This problem was asked by Apple.

Description

You are given a binary tree representation of an arithmetic expression. In this tree, each leaf is an integer value, and a non-leaf node is one of the four operations: '+', '-', '*', or '/'.

Write a function that takes this tree and evaluates the expression.

Example

Input:
    *
   / \
  +    +
 / \  / \
3  2  4  5

Output:
45 # (3 + 2) * (4 + 5)