标签:geo ack etc empty div level eve levels tor
题目
1 class Solution { 2 public: 3 vector<double>ans; 4 vector<double> averageOfLevels(TreeNode* root) { 5 if(!root) return ans; 6 queue<TreeNode*>q; 7 q.push(root); 8 while(!q.empty()){ 9 int num = q.size();double sum = 0; 10 for(int i = 0;i < num;i++){ 11 TreeNode* node = q.front();q.pop(); 12 sum += node->val; 13 if(node->left!=NULL) q.push(node->left); 14 if(node->right!=NULL) q.push(node->right); 15 } 16 ans.push_back(sum/num); 17 } 18 return ans; 19 } 20 };
标签:geo ack etc empty div level eve levels tor
原文地址:https://www.cnblogs.com/fresh-coder/p/14262664.html