leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0515.cpp (602B)
0 class Solution {
1 public:
2 vector<int> largestValues(const TreeNode *root) {
3 if (!root) return {};
5 vector<int> res;
6 queue<const TreeNode *> q({root});
7 while (!q.empty()) {
8 int maxi = INT_MIN;
9 for (int k = q.size(); k > 0; k--) {
10 const TreeNode *root = q.front();
11 q.pop();
12 maxi = max(maxi, root->val);
13 if (root->left) q.push(root->left);
14 if (root->right) q.push(root->right);
15 }
16 res.push_back(maxi);
17 }
18 return res;
19 }
20 };