#C5633. Collect Leaf Nodes from a Binary Tree

    ID: 49304 Type: Default 1000ms 256MiB

Collect Leaf Nodes from a Binary Tree

Collect Leaf Nodes from a Binary Tree

You are given a binary tree represented in level-order as a list. Each element corresponds to a node’s value and missing nodes are denoted by null (or None), meaning that the child is absent.

The binary tree is indexed in the usual way: the left child of the node at index \(i\) is at index \(2i+1\) and the right child is at index \(2i+2\). A leaf node is defined as a node with no children.

Your task is to output the values of all leaf nodes in left-to-right order.

inputFormat

A single line containing space-separated tokens representing the binary tree in level-order. Each token is either an integer or the string 'null' (case-insensitive) indicating an absent node.

outputFormat

Print the values of all leaf nodes in left-to-right order, separated by a single space. If there are no leaf nodes, output an empty line.## sample

1
1