w Explanation||Simple DFS C++ solution
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    // Initialize the sum vector with INT_MIN at index 0\n    vector<int> sum = {INT_MIN};\n    \n    // Depth-first search function to calculate the sum at each level\n    void dfs(TreeNode* Node, int level){\n        // Base case: If the current node is null, return\n        if (Node == NULL) return;\n        \n        // If the sum vector size is equal to the current level,\n        // add the node\'s value to the sum vector\n        if (sum.size() == level) sum.push_back(Node->val);\n        else sum[level] += Node->val;\n        \n        // Recursively call the dfs function for the left and right child nodes\n        dfs(Node->left, level+1);\n        dfs(Node->right, level+1);\n    }\n    \n    // Main function to find the level with the maximum sum in the binary tree\n    int maxLevelSum(TreeNode* root) {\n        // Call the dfs function to calculate the sum at each level\n        dfs(root, 1);\n        \n        // Find the maximum element in the sum vector\n        // and return its index\n        return max_element(sum.begin(), sum.end()) - sum.begin();\n    }\n};\n\n```
['Binary Tree', 'C++']