INT_MIN、INT_MAX
mid = l + (r -l) / 2
(r -l) /2 向下取整 1/2 = 0,如果向上取整,被除数+1即可, (r -l+1) /2
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> ret;
if (root == nullptr) {
return ret;
}
queue <TreeNode*> q;
q.push(root);
while (!q.empty()) {
int n = q.size();
vector<int> vec;
for (int i =0; i <n; ++i) {
TreeNode* t = q.front();
q.pop();
vec.push_back(t->val);
if (t->left) q.push(t->left);
if (t->right) q.push(t->right);
}
ret.push_back(vec);
}
return ret;
}
};