Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
class Solution {public: vector largestValues(TreeNode* root) { vector ans; if (!root) { return ans; } queue q{{root}}; while (q.size()) { int x = INT_MIN; for (int i = q.size(); i; --i) { TreeNode* node = q.front(); q.pop(); x = max(x, node->val); if (node->left) { q.push(node->left); } if (node->right) { q.push(node->right); } } ans.push_back(x); } return ans; }};
class Solution {
public:
vector largestValues(TreeNode* root) {
vector ans;
if (!root) {
return ans;
}
queue q{{root}};
while (q.size()) {
int x = INT_MIN;
for (int i = q.size(); i; --i) {
TreeNode* node = q.front();
q.pop();
x = max(x, node->val);
if (node->left) {
q.push(node->left);
}
if (node->right) {
q.push(node->right);
}
}
ans.push_back(x);
}
return ans;
}
};