当前位置:网站首页>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;
}边栏推荐
- Nmap进行主机探测出现网段IP全部存活情况分析
- RPA super automation | nongnongji and cloud expansion accelerate financial intelligent operation
- 《物联网开发实战》18 场景联动:智能电灯如何感知光线?(上)(学习笔记)
- All inherited features
- Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)
- 实验10 Bezier曲线生成-实验提高-交互式生成B样条曲线
- 判断大小端存储两种办法
- Top - k问题
- 为什么需要微服务
- 科普 | NFT的类型有哪些(上)
猜你喜欢

RPA超自动化 | 农耕记携手云扩加速财务智能化运营

即将首发 | 业界首个零售数字化创新白皮书,解锁全链路数字化致胜秘籍

领先企业推进智慧财务的同款效率工具,赶快了解一下?

华为设备配置H-VPN

Top - k问题

类和对象(2)

The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success

JVM | runtime data area; Program counter (PC register);

Carry and walk with you. Have you ever seen a "palm sized" weather station?

如何利用RPA机器人开启货代行业数字化转型第一步?
随机推荐
Leetcode-155-minimum stack
Redis Foundation
带有 ceph-csi 的静态 PVC
Leetcode-104- maximum depth of binary tree
Redis transaction
JVM class loader; Parental delegation mechanism
R语言书籍学习03 《深入浅出R语言数据分析》-第八章 逻辑回归模型 第九章 聚类模型
每日一题 -- 验证回文串
206.反转链表
相对完善的单例模式
Master of a famous school has been working hard for 5 years. AI has no paper. How can the tutor free range?
Classes and objects (4)
Go encoding package
[niuke.com] ky41 put apples
R语言书籍学习03 《深入浅出R语言数据分析》-第十二章 支持向量机 第十三章 神经网络
如何利用RPA机器人开启货代行业数字化转型第一步?
R language book learning 03 "in simple terms R language data analysis" - Chapter 12 support vector machine Chapter 13 neural network
Why microservices are needed
网络连接正常但百度网页打不开显示无法访问此网站解决方案
How to use RPA robot to start the first step of digital transformation of freight forwarding industry?