public TreeNode insertIntoBST(TreeNode root, int val) {if (root == null) {root = new TreeNode(val);return root;}TreeNode curNode = root;while (curNode != null) {if (curNode.val > val) {// 这里的思路没问题:// 当确定了左右子树之后,// 我们要直接判断当前节点的左右子树是否为 nullif (curNode.left == null) {curNode.left = new TreeNode(val);break;} else {curNode = curNode.left;}} else {if (curNode.right == null) {curNode.right = new TreeNode(val);break;} else {curNode = curNode.right;}}}return root;}
