Pergunta de entrevista da empresa Amazon

Say you have a binary tree (data, left, right). Write a method to find the height of the tree!

Resposta da entrevista

Sigiloso

14 de mar. de 2011

int height (Node root) { if (root == null) return 0; return 1 + Math.max(height(root.left), height(root.right)); } this was my answer and he seemed satisfied with it. He asked me to walk him through what would happen, given a tree.

3