Beat 85% 🔥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$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 */\nclass Solution {\npublic:\n    int levelOrder(TreeNode* root){\n        int ans=-1;\n        if(root==NULL){\n            return 0;\n        }\n        int level=1;\n        queue<TreeNode*>q;\n        q.push(root);\n        int maxi=INT_MIN;\n        while(!q.empty()){\n            int size=q.size();\n            int sum=0;\n            while(size--){\n                TreeNode* top=q.front();\n                q.pop();\n                sum+=top->val;\n                if(top->left!=NULL){\n                    q.push(top->left);\n                }\n                if(top->right!=NULL){\n                    q.push(top->right);\n                }\n            }\n            if(maxi<sum){\n                maxi=sum;\n                ans=level;\n            }\n            level++;\n        }\n        return ans;\n    }\n    int maxLevelSum(TreeNode* root){\n        return levelOrder(root);\n    }\n};\n```
['C++']