[ C++ ] [ BFS ]
Code\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : 
# 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 */\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n        int ans;\n        int maxsum = INT_MIN;\n        if(root == NULL) return ans;\n        queue<TreeNode*> q;\n        q.push(root);\n        int level = 1;\n        while(!q.empty()){\n            int sum = 0;\n            int size = q.size();\n            for(int i = 0; i < size; i++){\n                TreeNode* curr = q.front();\n                q.pop();\n                sum += curr->val;\n                if(curr->left != NULL) q.push(curr->left);\n                if(curr->right != NULL) q.push(curr->right);\n            }\n            if(sum > maxsum){\n                ans = level;\n                maxsum = max(sum,maxsum);\n            }\n            level++;\n        }\n        return ans;        \n    }\n};\n```
['C++']