Simple C++ solution with map
\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n        search(root, 1);\n\n        int bestLevel = 1;\n        for (const auto &p : sums) {
```\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n        search(root, 1);\n\n        int bestLevel = 1;\n        for (const auto &p : sums) {\n            // the map sums is iterated in order of levels\n            if (p.second > sums[bestLevel]) {\n                bestLevel = p.first;\n            }\n        }\n        return bestLevel;\n    }\nprivate:\n    void search(TreeNode* root, const int level) {\n        if (!root) {\n            return;\n        }\n\n        sums[level] += root->val;\n        search(root->left , level+1);\n        search(root->right, level+1);\n    }\n\n    map<int, int> sums; // level : sum\n};\n```
[]