diff --git a/515. Find Largest Value in Each Tree Row1 b/515. Find Largest Value in Each Tree Row1 new file mode 100644 index 0000000..2d471c1 --- /dev/null +++ b/515. Find Largest Value in Each Tree Row1 @@ -0,0 +1,23 @@ +class Solution { +public: + vector largestValues(TreeNode* root) { + queue q; + if(root==NULL) return {}; + q.push(root); + vector res; + while (!q.empty()) { + int n = q.size(), maxi = INT_MIN; + for (int i = 0; i < n; i++) { + TreeNode* node = q.front(); + q.pop(); + maxi = max(maxi, node->val); + if (node->left) + q.push(node->left); + if (node->right) + q.push(node->right); + } + res.push_back(maxi); + } + return res; + } +};