C++ Solution
Approach\n Describe your approach to solving the problem. \n     BFS\n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n    O(N)\n
# Approach\n<!-- Describe your approach to solving the problem. -->\n     BFS\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(N)\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\n\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n        int maxSum = INT_MIN;\n        int ans = 0, level = 0;\n        queue<TreeNode*> q;\n        q.push(root);\n        while (!q.empty()) {\n            level++;\n            int sz = q.size(), sum = 0;\n            while (sz--) {\n                TreeNode* node = q.front();\n                q.pop();\n                sum += node->val;\n                if (node->left) q.push(node->left);\n                if (node->right) q.push(node->right);\n            }\n            if (maxSum < sum) {\n                maxSum = sum;\n                ans = level;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']