LeetCode-Solutions-in-Cpp17

Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.


Project maintained by downdemo Hosted on GitHub Pages — Theme by mattgraham
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;
  }
};