class Node {
public Node left;
public int data;
public Node right;
public Node(int val) {
this.data = val;
}
@Override
return this.data + "";
}
}
class LeftView {
public static int maxLevel = 0;
public void leftView(Node root, int level) {
if (root == null)
return;
if (maxLevel < level) {
System.
out.
println(root.
data); maxLevel = level;
}
leftView(root.left, level + 1);
leftView(root.right, level + 1);
}
public static void main
(String[] args
) { Node root = new Node(1);
root.left = new Node(2);
root.left.left = new Node(4);
root.left.right = new Node(5);
root.left.right.left = new Node(7);
root.left.right.right = new Node(8);
root.left.right.left.left = new Node(9);
root.right = new Node(3);
root.right.left = new Node(6);
root.right.right = new Node(7);
LeftView obj = new LeftView();
obj.leftView(root, 1);
}
}
Y2xhc3MgTm9kZSB7CglwdWJsaWMgTm9kZSBsZWZ0OwoJcHVibGljIGludCBkYXRhOwoJcHVibGljIE5vZGUgcmlnaHQ7CgoJcHVibGljIE5vZGUoaW50IHZhbCkgewoJCXRoaXMuZGF0YSA9IHZhbDsKCX0KCglAT3ZlcnJpZGUKCXB1YmxpYyBTdHJpbmcgdG9TdHJpbmcoKSB7CgkJcmV0dXJuIHRoaXMuZGF0YSArICIiOwoJfQp9CgogY2xhc3MgTGVmdFZpZXcgewoKCXB1YmxpYyBzdGF0aWMgaW50IG1heExldmVsID0gMDsKCglwdWJsaWMgdm9pZCBsZWZ0VmlldyhOb2RlIHJvb3QsIGludCBsZXZlbCkgewoJCWlmIChyb290ID09IG51bGwpCgkJCXJldHVybjsKCgkJaWYgKG1heExldmVsIDwgbGV2ZWwpIHsKCQkJU3lzdGVtLm91dC5wcmludGxuKHJvb3QuZGF0YSk7CgkJCW1heExldmVsID0gbGV2ZWw7CgkJfQoKCQlsZWZ0Vmlldyhyb290LmxlZnQsIGxldmVsICsgMSk7CgkJbGVmdFZpZXcocm9vdC5yaWdodCwgbGV2ZWwgKyAxKTsKCX0KCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgkJTm9kZSByb290ID0gbmV3IE5vZGUoMSk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