-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path637.py
More file actions
25 lines (25 loc) · 717 Bytes
/
Copy path637.py
File metadata and controls
25 lines (25 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
import Queue;
class Solution(object):
def averageOfLevels(self, root):
"""
:type root: TreeNode
:rtype: List[float]
"""
res = [];
que = [root];
while que:
res.append(1.0 * sum([n.val for n in que])/len(que));
tmpq = [];
for node in que:
if node.left != None:
tmpq.append(node.left);
if node.right != None:
tmpq.append(node.right);
que = tmpq;
return res;