Take it easy, sit back and relax

For regular traversal, you can simply use a queue. Note the creation and usage of the Java queue.
[!NOTE]
The creation of a Java queue is generally done usingLinkedList, for example,Queue<TreeNode> q = new LinkedList<>();
add()andoffer()are used to add elements to the end of the queue;offer()is safer, whileadd()will throw an exception if the queue is full.
poll()removes and returns the head element of the queue, equivalent to combining C++'sfront()andpop().
peek()returns the head element of the queue but does not remove it.
size()returns the number of elements in the queue;isEmpty()checks if the queue is empty.
contains(Object o)checks if the queue contains a specific element.
Code: