C# solution doesn't compile


  • 0
    C

    ''''
    public int DepthSum(IList<NestedInteger> nestedList)
    {
    return DepthSumUtil(nestedList, 1);
    }

    public int DepthSumUtil(IList<NestedInteger> nestedList, int depth)
        { 
            int sum = 0;
            foreach (NestedInteger nestedInt in nestedList)
            {
                if (nestedInt.isInteger())
                {
                    sum += nestedInt.getInteger() * depth;
                }
                else
                {
                    sum += DepthSumUtil(nestedInt.getList(), depth + 1);
                }
            }
    
            return sum;
        }
    

    ''''

    The error I get is: Cannot implicitly convert type System.Collections.Generic.IList<NestedInteger> [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]' toSystem.Collections.Generic.IList<NestedInteger> [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]'. An explicit conversion exists (are you missing a cast?)

    It seems to be an issue with the C# compiler. Can someone from LeetCode have a look please?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.