当前位置:网站首页>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
边栏推荐
- [Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
- Charles function introduction and use tutorial
- How can swagger2 custom parameter annotations not be displayed
- SQL Server recursive query of superior and subordinate
- Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file
- 19. Delete the penultimate node of the linked list (linked list)
- Yarn core parameter configuration
- JUC concurrent programming 09 -- source code analysis of condition implementation
- Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis
- Chapter 120 SQL function round
猜你喜欢

一文看懂 LSTM(Long Short-Term Memory)

Introduction to data analysis 𞓜 kaggle Titanic mission (IV) - > data cleaning and feature processing

Zhengda international explains what the Dow Jones industrial index is?

Download and installation steps of xshell + xftp

微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件

Reading integrity monitoring techniques for vision navigation systems - 5 Results

JVM - common parameters
MapReduce core and foundation demo

JUC concurrent programming 06 -- in-depth analysis of AQS source code of queue synchronizer

Chapter 120 SQL function round
随机推荐
209. Subarray with the smallest length (array)
Comparison and practice of prototype design of knowledge service app
206. Reverse linked list (linked list)
Read LSTM (long short term memory)
Read integrity monitoring techniques for vision navigation systems - 4 multiple faults in vision system
Arbitrary file reading vulnerability exploitation Guide
Is the pointer symbol of C language close to variable type or variable name?
高价买来的课程,公开了!phper资料分享
SSH利用私钥无密钥连接服务器踩坑实录
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
Chapter 120 SQL function round
定义链表(链表)
JVM——》常用命令
Idea - indexing or scanning files to index every time you start
19、删除链表的倒数第N个节点(链表)
Read integrity monitoring techniques for vision navigation systems
CSP certification 202203-2 travel plan (multiple solutions)
Using multithreading to output abc10 times in sequence
349. Intersection of two arrays
Deploy jar package