File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 2016-04-02 27 tests, 48 ms
2
+ # """
3
+ # Thi
EF4E
s is the interface that allows for creating nested lists.
4
+ # You should not implement it, or speculate about its implementation
5
+ # """
6
+ #class NestedInteger(object):
7
+ # def isInteger(self):
8
+ # """
9
+ # @return True if this NestedInteger holds a single integer, rather than a nested list.
10
+ # :rtype bool
11
+ # """
12
+ #
13
+ # def getInteger(self):
14
+ # """
15
+ # @return the single integer that this NestedInteger holds, if it holds a single integer
16
+ # Return None if this NestedInteger holds a nested list
17
+ # :rtype int
18
+ # """
19
+ #
20
+ # def getList(self):
21
+ # """
22
+ # @return the nested list that this NestedInteger holds, if it holds a nested list
23
+ # Return None if this NestedInteger holds a single integer
24
+ # :rtype List[NestedInteger]
25
+ # """
26
+
27
+ class Solution (object ):
28
+ def depthSum (self , nestedList ):
29
+ """
30
+ :type nestedList: List[NestedInteger]
31
+ :rtype: int
32
+ """
33
+ def scanList (curr_list , depth ):
34
+ return sum (depth * x .getInteger () if x .isInteger () else scanList (x .getList (), depth + 1 ) for x in curr_list )
35
+
36
+ return scanList (nestedList , 1 )
You can’t perform that action at this time.
0 commit comments