6
private int count(TreeNode root) {7
if (root == null) return 0;8
return 1 + count(root.left) + count(root.right);11
public CBTInserter(TreeNode root) {16
private int insertBinary(int val, int k, int right) {19
while (left < right) {20
if (left == right - 1) {21
if (ptr.left == null) ptr.left = new TreeNode(val);22
else ptr.right = new TreeNode(val);25
int mid = (right - left) / 2 + left;37
public int insert(int val) {44
if ((1 << depth) - 1 == total) depth++;45
// k is the new index in the lowest level of tree, right is the max index of the lowest level of52
// it's insertBinary(val, 1, 1)53
var res = insertBinary(val, total - (1 << (depth - 1)) + 1, (1 << (depth - 1)) - 1);58
public TreeNode get_root() {