当前位置:网站首页>A diary of dishes | 238 Product of arrays other than itself
A diary of dishes | 238 Product of arrays other than itself
2022-04-23 10:34:00 【Ape knowledge】

Series index : Writing diary of vegetables | By LeetCode use Python The days of abuse
The way of cultivating immortality of vegetable chicken ——2022/1/12
List of articles
【 subject 】
Give you a length of n Array of integers for nums, among n > 1, Return output array output , among output[i] be equal to nums Middle Division nums[i] Product of other elements .
Example :
Input : [1,2,3,4]
Output : [24,12,8,6]
Tips : The title data guarantees all prefix elements and suffixes of any element in the array ( Even the entire array ) The product of is all in 32 Bit integer range .
explain : Please do not use division , And in O(n) Complete this question in time complexity .
Topic link :https://leetcode-cn.com/problems/product-of-array-except-self/
【 Official thinking 】
Old rules , It depends on the official solution . I have to say that it's interesting to see the boss solve the problem 、

Method 1 : Construct two lists to store the product of prefix and suffix respectively ,anwser It's the product of the two , Three times in total .

Advanced : Advanced repeated borrowing anwser To save space and complexity , Use here R To temporarily store suffix product data , Get a new R Then take it directly to anwser In the . Play a “ One for one group ” The role of .

The code can be studied , From the video .
【 Reference code 】
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
res = [1 for i in range(len(nums))]
left = 1
for i in range(len(nums)):
res[i] *= left
left *= nums[i]
right = 1
for i in range(len(nums)-1, -1, -1):
res[i] *= right
right *= nums[i]
return res
【 reflection 】
Have to say , I feel ashamed that I have been reading computer code for nearly three years , Although the Internet of things is biased towards engineering practice , But from the perspective of personal planning, we still need to improve our algorithm level , come on. , It's never too late to learn !
Python The series of force buckle problem solving is continuously updated , welcome
Like collection+Focus on
Last one : Writing diary of vegetables | 189. Rotation array rotate-array
Next : Writing diary of vegetables | 118. Yang hui triangle
My level is limited , Please comment and correct the deficiencies in the article in the comment area below ~If feelings help you , Point a praise Give me a hand ~
Share... From time to time Interesting 、 Have a material 、 Nutritious content , welcome Subscribe to follow My blog , Looking forward to meeting you here ~
版权声明
本文为[Ape knowledge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230619310121.html
边栏推荐
- Go language practice mode - functional options pattern
- Realizing data value through streaming data integration (4) - streaming data pipeline
- SQLServer 查询数据库死锁
- Solve the problem of installing VMware after uninstalling
- Jerry's factors that usually affect CPU performance test results are: [article]
- /Can etc / shadow be cracked?
- 707. Design linked list (linked list)
- Contact between domain name and IP address
- 707、设计链表(链表)
- 【leetcode】199. Right view of binary tree
猜你喜欢

SQL Server 递归查询上下级

SQL Server cursor circular table data

Sim Api User Guide(5)

得到知识服务app原型设计比较与实践

Comparison and practice of prototype design of knowledge service app

SQL Server recursive query of superior and subordinate

【省选联考 2022 D2T1】卡牌(状态压缩 DP,FWT卷积)
Detailed explanation of MapReduce calculation process

Swagger2 自定义参数注解如何不显示

解决方案架构师的小锦囊 - 架构图的 5 种类型
随机推荐
SQL Server cursor circular table data
【leetcode】107.二叉树的层序遍历II
Realizing data value through streaming data integration (5) - flow analysis
Introduction to data analysis 𞓜 kaggle Titanic mission (IV) - > data cleaning and feature processing
SQL server query database deadlock
Charles function introduction and use tutorial
解决方案架构师的小锦囊 - 架构图的 5 种类型
349、两个数组的交集
LeetCode 1249. Minimum remove to make valid parents - FB high frequency question 1
Deploy jar package
997、有序数组的平方(数组)
[Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
What are the system events of Jerry's [chapter]
Contact between domain name and IP address
202. Happy number
Jerry's users how to handle events in the simplest way [chapter]
高价买来的课程,公开了!phper资料分享
【leetcode】107. Sequence traversal of binary tree II
得到知识服务app原型设计比较与实践
Download and installation steps of xshell + xftp