leetcode-hard-array-238. Product of Array Except Self-NO
mycode 99.47%
class Solution(object):
def productExceptSelf(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
temp =
res = list()
res.append()
#nums的第一个数和最后一个数是最特殊的,因为别人都是左右可以包围的,即product=该数前面所有数的乘积*该数后面所有数的乘积
#所以res[]放1,代表nums[]前面的数(其实没有)的product
for i in range(len(nums)-):
#当i为len(nums)-2时,计算出来的乘积就是nums最后一个元素的product结果
temp *= nums[i]
res.append(temp) #res[]放的时nums[]前面的数的product
#i==len(nums)-2时,res[len(nums)-]放的就是nums[-]前面的数的product,而nums[-]后面是没有数的,所有逆向遍历的时候只需要从nums[len(nums)-]开始计算它后面的乘积
temp =
for i in range(len(nums)-,-,-):
temp *= nums[i+]
res[i] = res[i]*temp
return res
leetcode-hard-array-238. Product of Array Except Self-NO的更多相关文章
- LeetCode OJ 238. Product of Array Except Self 解题报告
题目链接:https://leetcode.com/problems/product-of-array-except-self/ 238. Product of Array Except Se ...
- LN : leetcode 238 Product of Array Except Self
lc 238 Product of Array Except Self 238 Product of Array Except Self Given an array of n integers wh ...
- leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II
11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情 ...
- 238. Product of Array Except Self(对O(n)和递归又有了新的理解)
238. Product of Array Except Self Total Accepted: 41565 Total Submissions: 97898 Difficulty: Med ...
- 【LeetCode】238. Product of Array Except Self
Product of Array Except Self Given an array of n integers where n > 1, nums, return an array outp ...
- leetcode:238. Product of Array Except Self(Java)解答
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Product of Array Except Self Given an array of n integers where n > ...
- 【刷题-LeetCode】238. Product of Array Except Self
Product of Array Except Self Given an array nums of n integers where n > 1, return an array outpu ...
- [LeetCode] 238. Product of Array Except Self 除本身之外的数组之积
Given an array nums of n integers where n > 1, return an array output such that output[i] is equ ...
- LeetCode 238. Product of Array Except Self (去除自己的数组之积)
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...
- 【LeetCode】238. Product of Array Except Self 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 两次遍历 日期 题目地址:https://leetcode.c ...
随机推荐
- 【Zabbix】分布式监控系统Zabbix【一】
一.Zabbix功能及特性简介 Zabbix可以获取cpu,内存,网卡,磁盘,日志等信息 1.Zabbix数据收集方式: a.Agent客户端(Agent客户端支持多平台部署) b.如果是无法安装客户 ...
- 启动Activity的单独事件方法2
1.Button中创建android:onClick="sendmessage" sendmessage方法名 //MAIN_acitivity创建这个同名独立方法 响应Butto ...
- redis-数据淘汰策略
博客标题:Redis的数据淘汰策略及相关注意事项 配置redis.conf中的maxmemory这个值来开启内存淘汰功能 volatile-lru:从已设置过期时间的数据集(server.db[i]. ...
- 8.CNN应用于手写字识别
import numpy as np from keras.datasets import mnist from keras.utils import np_utils from keras.mode ...
- Java语言基础(14)
1 访问控制修饰符(二) 1)public:公共的,可以用来修饰类,属性,构造方法以及方法,被public修饰的类,属性,构造方法以及方法,可以任意的进行访问. 2)private:私有的,可以用来修 ...
- 批量删除Zen Cart 无图片商品
<?php /** * * @ 批量删除Zen Cart 无图片商品 * @ 使用方法: 将本文件上传到网站根目录下运行 http://你的域名/zcdelpro.php * @ $status ...
- 打成jar包运行,依然可以找到指定路径的xml
今天遇到一个问题,解决了就想着记下来 无效: getClass().getClassLoader().getResource("ehcache.xml").getPath() 有效 ...
- JQuery实现简单的服务器轮询效果
很多论坛都有进入后,弹出提示,说有多少封邮件没有看,或者是一个oa系统,进入后,提示有多少个任务没有做.每隔一段时间会提示一次,但是如何实现呢.其实,利用jquery的话,会比较简单,核心元素就是js ...
- MySQL 将数据文件分布到不同的磁盘
https://blog.csdn.net/john_chang11/article/details/51783632 [root@test1 temp]# vi /etc/my.cnf [mysql ...
- python中ord()函数,chr()函数,unichr()函数
ord()函数,chr()函数,unichr()函数 chr()函数用一个范围在range(256)内的(就是0-255)整数作参数,返回一个对应的字符.unichr()跟它一样,只不过返回的是Uni ...