public static Queue<Integer> bfs(TreeNode root){
Queue<Integer> queue=new LinkedList<>();
Queue<TreeNode> help=new LinkedList<>();
help.offer(root);
while (!help.isEmpty()){
TreeNode poll = help.poll();
queue.offer(poll.val);
if(poll.left!=null) help.offer(poll.left);
if(poll.right!=null) help.offer(poll.right);
}
return queue;
}
public static class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {
}
TreeNode(int val) {
this.val = val;
}
TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
}