2 3 4 5 6 7 8 9 10
# File 'lib/binary_trees.rb', line 2 def to_root(i = 0) root = nil if i < self.length root = TreeNode.new(self[i]) root.left = to_root(i * 2 + 1) root.right = to_root(i * 2 + 2) end root end