当前位置:网站首页>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
边栏推荐
- What are Jerry's usual program exceptions? [chapter]
- 任意文件读取漏洞 利用指南
- 2022 mobile crane driver test question bank simulation test platform operation
- 一文看懂 LSTM(Long Short-Term Memory)
- C#和数据库连接中类的问题
- Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis
- Contact between domain name and IP address
- Jerry's factors that usually affect CPU performance test results are: [article]
- 997. Square of ordered array (array)
- 【leetcode】107. Sequence traversal of binary tree II
猜你喜欢
基于PyQt5实现弹出任务进度条功能示例
Introduction to data analysis 𞓜 kaggle Titanic mission (IV) - > data cleaning and feature processing
/Can etc / shadow be cracked?
SSH利用私钥无密钥连接服务器踩坑实录
Comparison and practice of prototype design of knowledge service app
Solve the problem of installing VMware after uninstalling
/etc/shadow可以破解吗?
lnmp的配置
第120章 SQL函数 ROUND
mysql同一个表中相同数据怎么合并
随机推荐
142. Circular linked list||
一文看懂 LSTM(Long Short-Term Memory)
微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
24. Exchange the nodes in the linked list (linked list)
Art template template engine
任意文件读取漏洞 利用指南
【leetcode】107.二叉树的层序遍历II
二叉树的构建和遍历
Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file
Read integrity monitoring techniques for vision navigation systems - 4 multiple faults in vision system
Realizing data value through streaming data integration (5) - stream processing
Comparison and practice of prototype design of knowledge service app
Jinglianwen technology - professional data annotation company and intelligent data annotation platform
Chapter I Oracle database in memory related concepts (Continued) (im-1.2)
Sim Api User Guide(4)
Read LSTM (long short term memory)
【省选联考 2022 D2T1】卡牌(状态压缩 DP,FWT卷积)
SQL tuning series - Introduction to SQL tuning
MapReduce core and foundation demo
LeetCode 1249. Minimum remove to make valid parents - FB high frequency question 1