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 ...
随机推荐
- Mysql(四)-2:多表查询
一 介绍 本节主题 多表连接查询 复合条件连接查询 子查询 准备表 #建表 create table department( id int, name varchar(20) ); create ta ...
- VM虚拟机下centos安装。
centOS 7安装步骤: 1.选择新建虚拟机,稍后安装,linux选centos7 64位 2.位置改到存放虚拟机的文件夹 3.把硬盘空间改到40g,内存分到4g,1处理器2个核心 4 更改cd/d ...
- Linux CentOS 7 防火墙与端口设置操作
CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...
- 生产问题之StackOverflowError异常小记
印象中,这是项目中首次遇到 StackOverflowError,在此做个笔记. (吃饭回来写) …… 吃饭回来后,尝试把代码回退来分析异常产生原因,然而却无法复现这个栈溢出异常……醉了 有缘再见再写 ...
- PHP类知识----值传递和引用传递
JS中数组是引用传递 PHP除了资源和对象等数据类型,其数据类型是值传递(即使数组也如此) 栈内存(快速内存)中存放标量数据类型,复合数据类型的变量名和数据地址 在内存中,我们可以认为内存中有很多格子 ...
- JDK8日期处理API(转)
转载地址:http://www.cnblogs.com/comeboo/p/5378922.html 转载地址:http://blog.csdn.net/hspingcc/article/detail ...
- 第一篇【Zabbix服务端的完整布署】
1.环境准备 服务器版本: [root@filestore-v2 ~]# cat /etc/redhat-release CentOS Linux release (Core) 内核版本: [root ...
- [Python自学] day-16 (JS、作用域、DOM、事件)
一.JS中的三种函数 1.普通函数 function func(){ console.log("Hello World"); } func() 2.匿名函数 setInterval ...
- 【Python之路】特别篇--Python文件操作
文件操作 open函数,该函数用于文件处理 操作文件时,一般需要经历如下步骤: (1)打开文件 (2)操作文件 一.打开文件 文件句柄 = open('文件路径', '模式','编码') 打开文件时, ...
- Dungeon Master (POJ - 2251)(BFS)
转载请注明出处: 作者:Mercury_Lc 地址:https://blog.csdn.net/Mercury_Lc/article/details/82693907 题目链接 题解:三维的bfs,一 ...