leetcode/src/s0513_find_bottom_left_tree_value.cpp
Sainnhe Park c442846324
All checks were successful
ci/woodpecker/push/test Pipeline was successful
s0513
2023-01-31 12:28:03 +08:00

21 lines
477 B
C++

#include "s0513_find_bottom_left_tree_value.hpp"
int findBottomLeftValue(TreeNode* root) {
int result{0};
queue<TreeNode *> q;
if (root) q.push(root);
int size{0};
TreeNode *front = root;
while (!q.empty()) {
size = q.size();
for (int i{0}; i < size; ++i) {
front = q.front();
q.pop();
if (i == 0) result = front->val;
if (front->left) q.push(front->left);
if (front->right) q.push(front->right);
}
}
return result;
}