原题题目
代码实现(首刷自解)
#define MAX 10001
#define MIN -9999999999int maxLevelSum(struct TreeNode* root){
int maxsum = MIN,tempsum,size,top = -1,rear = -1,level = 1,maxlevel = 0;struct TreeNode* queue[MAX];struct TreeNode* position;queue[++rear] = root;while(rear != top){
size = rear - top;tempsum = 0;while(size--){
position = queue[++top];tempsum += position->val;if(tempsum > maxsum && !size){
maxlevel = level;maxsum = tempsum;}if(position->left)queue[++rear] = position->left;if(position->right)queue[++rear] = position->right;}level++;}return maxlevel;
}