Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
queue<TreeNode*> q;
q.emplace(root);
int res;
while (!empty(q)) {
int n = size(q);
res = q.front()->val;
for (int i = 0; i < n; ++i) {
TreeNode* t = q.front();
q.pop();
if (t->left) {
q.emplace(t->left);
}
if (t->right) {
q.emplace(t->right);
}
}
}
return res;
}
};