Just treat the Nested List as a tree, and dfs it:
private int sum =0; public int depthSum(List<NestedInteger> nestedList) { helper(nestedList, 1); return sum; } private void helper(List<NestedInteger> nestedList, int level){ for(NestedInteger ni: nestedList){ if(ni.isInteger()){ sum+= ni.getInteger()*level; }else{ List<NestedInteger> list = ni.getList(); helper(list, level+1); } } }