给定一个嵌套的整数列表,返回列表中所有整数的总和,按它们的深度加权
例如,给定列表 {{1,1},2,{1,1}},函数应返回 10(深度 2 处有四个 1,深度 1 处有一个 *2)
给定列表 {1,{4,{6}}},函数应返回 27(深度 1 为 1,深度 2 为 4,深度 3 为 *6)
public int depthSum (List<NestedInteger> input)
{
//Implement this function
}
/**
* This is the interface that allows for creating nested lists. You should not implement it, or speculate about its implementation
*/
public interface NestedInteger
{
// Returns true if this NestedInteger holds a single integer, rather than a nested list
public boolean isInteger();
// Returns the single integer that this NestedInteger holds, if it holds a single integer
// Returns null if this NestedInteger holds a nested list
public Integer getInteger();
// Returns the nested list that this NestedInteger holds, if it holds a nested list
// Returns null if this NestedInteger holds a single integer
public List<NestedInteger> getList();
}