How do I take input in this question as it says levelOrder input will be given?
Tree Left View Doubt
hey @ap8730390
use Queue Data Structure
private Node createNode() {
int d = sc.nextInt();
LinkedList q = new LinkedList<>();
Node nn = new Node();
nn.data = d;
this.root = nn;
q.add(root);
while (!q.isEmpty()) {
Node node = q.getFirst();
q.removeFirst();
int c1 = sc.nextInt();
int c2 = sc.nextInt();
if (c1 != -1) {
nn = new Node();
nn.data = c1;
node.left = nn;
q.addLast(node.left);
}
if (c2 != -1) {
nn = new Node();
nn.data = c2;
node.right = nn;
q.addLast(node.right);
}
}
return root;
}