给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。

示例:

输入: [1,2,3,4]
输出: [24,12,8,6]
说明: 请不要使用除法,且在 O(n) 时间复杂度内完成此题。

class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
ln =len(nums)
left,right = []*ln,[]*ln
for i in range(,ln):
left[i] = left[i-]*nums[i-] #left = [, , , ]
right[ln-i-] = right[ln-i]*nums[ln-i] #right = [, , , ]
res = []*ln
for i in range(ln):
res[i] = left[i]*right[i]
return res

参考:https://blog.csdn.net/weixin_43399785/article/details/88190888

leetcode 238. 除自身以外数组的乘积 (python)的更多相关文章

  1. LeetCode 238. 除自身以外数组的乘积(Product of Array Except Self)

    238. 除自身以外数组的乘积 238. Product of Array Except Self 题目描述 LeetCode LeetCode238. Product of Array Except ...

  2. Java实现 LeetCode 238 除自身以外数组的乘积

    238. 除自身以外数组的乘积 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元 ...

  3. [leetcode]238. 除自身以外数组的乘积

    题目描述 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输 ...

  4. LeetCode 238. 除自身以外数组的乘积( Product of Array Except Self)

    题目描述 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输 ...

  5. [LeetCode] 238. 除自身以外数组的乘积 ☆☆☆(左积*右积)

    描述 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输入: ...

  6. Leetcode题目238.除自身以外数组的乘积(中等)

    题目描述: 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: ...

  7. leecode 238除自身以外数组的乘积

    class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { //用除法必须要 ...

  8. leetcode NO.349 两个数组的交集 (python实现)

    来源 https://leetcode-cn.com/problems/intersection-of-two-arrays/ 题目描述 给定两个数组,写一个函数来计算它们的交集. 例子: 给定 nu ...

  9. 剑指offer 66. 构建乘积数组(Leetcode 238. Product of Array Except Self)

    剑指offer 66. 构建乘积数组 题目: 给定一个数组A[0, 1, ..., n-1],请构建一个数组B[0, 1, ..., n-1],其中B中的元素B[i] = A[0] * A[1] * ...

随机推荐

  1. 2019春第十二周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 这里 我在这个课程的目标是 能按自己的想法解出题目 这个作业在那个具体方面帮助我实现目标 能朝着软件工程师方向发展 参考文献与网址 C语言 ...

  2. 多线程03-Abort

        );             t.Abort();             Console.WriteLine(; i < ; i++)             {            ...

  3. Mock接口数据 = mock服务 + iptable配置

    一.mock接口数据应用场景: 1.测试接口A,A接口代码中调用其他服务的B接口,由于开发排期.测试环境不通等原因,依赖接口不可用 2.测试异常情况,依赖接口B返回的数据格式不对.返回None.超时等 ...

  4. [THUPC2018] 弗雷兹的玩具商店

    link $solution:$ 好久没写数据结构了,那就写道简单题吧! 可以发现 $m\leq 50$,所以可以去取在 $[l,r]$ 中当价格相同时愉悦值最高的做完全背包 $dp$ . 发现修改价 ...

  5. BCR-ABL融合基因及检测

    费城染色体 费城染色体(Philadelphia chromosome, Ph (or Ph') chromosome),或称费城染色体易位(Philadelphia translocation),是 ...

  6. 20191126PHP连接数据(1)

    引进数据 mysql> create database stu1 character set utf8; mysql> use stu1 mysql> set names utf8; ...

  7. go中string类型转换为基本数据类型的方法

    代码 // string类型转基本数据类型 package main import ( "fmt" "strconv" ) func main() { str1 ...

  8. jQuery学习总结02-筛选

    一.筛选 1.eq(index|-index) 说明:获取当前链式操作中第N个jQuery对象,返回jQuery对象,类似的有get(index),不过get(index)返回的是DOM对象 示例: ...

  9. Dubbo源码学习总结系列七---注册中心

    Dubbo注册中心是框架的核心模块,提供了服务注册发现(包括服务提供者.消费者.路由策略.覆盖规则)的功能,该功能集中体现了服务治理的特性.该模块结合Cluster模块实现了集群服务.Dubbo管理控 ...

  10. linux 修改 rsyncd.conf 配置文件

    [root@rsync-server-1 ~]# cat > /etc/rsyncd.conf << EOF #Rsync server #created by sunsky 00: ...