12
返回列表 发新帖
楼主: assumption
跳转到指定楼层
上一主题 下一主题
收起左侧

脸熟onsite

🔗
fr42k 2019-3-9 11:07:03 | 只看该作者
全局:
请问3. 是不是 sum(前一次运算结果*当前值*当前深度)
回复

使用道具 举报

🔗
gzsgdtc123 2019-3-9 14:15:22 | 只看该作者
全局:
fr42k 发表于 2019-3-9 11:07
请问3. 是不是 sum(前一次运算结果*当前值*当前深度)

我觉着还是nestedList sum,只不过乘的不是depth,而是depth的阶乘depth!,code里只需要维护一个preProduct就行了class Solution(object):
    def depthSum(self, nestedList):
        """
        :type nestedList: List[NestedInteger]
        :rtype: int
        """
        data = []
        return self.getSum(nestedList, 1, 1)

    def getSum(self, nestedList, depth, preProduct):
        result = 0
        for subList in nestedList:
            if subList.isInteger():
                result += depth * subList.getInteger() * preProduct
            else:
                result += self.getSum(subList.getList(), depth + 1, preProduct * depth)
        return result


回复

使用道具 举报

全局:
点个赞吧,虽然看不到。。
回复

使用道具 举报

🔗
cynthiacao 2019-3-10 09:07:16 | 只看该作者
全局:
谢谢楼主提供的方法!
回复

使用道具 举报

🔗
tjuwdz95 2019-3-12 05:16:05 | 只看该作者
全局:
339 follow up啥意思啊楼主,是深度改成阶乘了么?给你加米了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表