当前位置:网站首页>238. product of arrays other than itself
238. product of arrays other than itself
2022-06-11 21:54:00 【Code loving students】
Title Description :
Give you an array of integers nums, return Array answer , among answer[i] be equal to nums Middle Division nums[i] Product of other elements .
Topic analysis :
We use the prefix and suffix method to solve this problem
For this problem, we can understand that we need to subscript i The previous subscript is 0~i-1 The element and subscript of are i+1~n Product of elements of .
For this problem, we can set an array to store the product of the elements before this element ( Prefix ).
Then multiply from the last element ( The tails are ).
The code implementation is as follows :
int* productExceptSelf(int* nums, int numsSize, int* returnSize){
int* a = (int*)malloc(numsSize*sizeof(int));// Set a new array
int add = 1;
for (int i = 0; i < numsSize; i++)
{
a[i] = add; // There is no element before the first element, so it stores 1( The product is itself )
add *= nums[i];
}
add = 1;
for (int i = numsSize - 1; i >= 0; i--)
{
a[i] *= add; // Product from back to front , The last element is stored as the product of all the previous elements , So by 1
add *= nums[i];
}
*returnSize = numsSize;
return a;
}边栏推荐
- Rexroth overflow valve zdb6vp2-42/315v
- The network connection is normal, but Baidu web page can not be opened and displayed. You can't access this website solution
- R语言书籍学习03 《深入浅出R语言数据分析》-第七章 线性回归模型
- C语言实现八种排序(1)
- [v2.1] automatic update system based on motion step API (repair bug, increase completion display, support disconnection reconnection and data compensation)
- Go IO module
- Leetcode-322- change exchange
- [today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
- Top - k问题
- 自定义实现offsetof
猜你喜欢

Add anti debugging function to game or code (application level)
![[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze](/img/eb/147d4aac20639d50b204dcf424c9e2.png)
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze

Leetcode-43- string multiplication

Leetcode-104- maximum depth of binary tree

如何利用RPA机器人开启货代行业数字化转型第一步?

Classes and objects (1)

Classes and objects (3)

How to use the transaction code sat to find the name of the background storage database table corresponding to a sapgui screen field

类与对象(3)

如何使用事物码 SAT 查找某个 SAPGUI 屏幕字段对应的后台存储数据库表的名称
随机推荐
All inherited features
继承的所有特征
快速排序的非递归写法
Sword finger offer 29 Print matrix clockwise
Add anti debugging function to game or code (application level)
Experiment 10 Bezier curve generation - experiment improvement - interactive generation of B-spline curve
How does the chief financial officer of RPA find the "super entrance" of digital transformation?
学习位段(1)
The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
How to view the installation date of the win system
Redis basic data type (Zset) ordered collection
Take off efficiently! Can it be developed like this?
[niuke.com] DP30 [template] 01 Backpack
【学术相关】申请审核制下,到双一流大学读博的难度有多大?
JVM | introduction
Nmap performs analysis of all network segment IP survivals in host detection
类和对象(4)
How to use RPA robot to start the first step of digital transformation of freight forwarding industry?
Flutter series: detailed explanation of container layout commonly used in flutter
实验10 Bezier曲线生成-实验提高-交互式生成B样条曲线