Leetcode 238:Product of Array Except Self

基于大疆TSDK与Pix4D的热红外数据工程化处理:从RJPG到温度正射影像的完整工作流 本文详细介绍了基于大疆TSDK与Pix4D的热红外数据工程化处理完整工作流。通过Python脚本自动化解析RJPG格式的热红外图像,提取并转换其中的原始辐射数据为包含真实温度信息的TIFF文件,再结合Pix4Dmapper进行批量拼接,最终生成可直接用于GIS分析的温度正射影像图。该流程解决了手动处理效率低下、参数校准复杂等难题,实现了从原始数据到定量分析成果的高效、准确、可重复生产。 阅读详情

Leetcode—238

Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

Solve it without division and in O(n).

For example, given [1,2,3,4], return [24,12,8,6].
【题目大意】给定一个数组a,需要返回一个数组b,数组b的第i个,也就是b[i]表示的是数组a中除了a[i]之外所有其他数字的乘积。
【要求】
1:不允许使用除法
2:O(n)的算法
【解法】
因为要求不能使用除法,所以最简便的一种方法就不可以了,就是先求出所有元素的和,然后用该总和除以每一位数。
其次,由于要求是O(n)的算法,所以分别求数组b中的每一个元素也不可能,那样话,要O(n^2)的时间复杂度。
所以需要一些技巧了:
我们来分析一下问题的解的结构:
b[0] = (a[1] * a[2] * a[3] * a[4] * a[5] * a[6] * ……)
b[1] = (a[0]) * (a[2] * a[3] * a[4] * a[5] * a[6] * ……)
b[2] = (a[0] * a[1]) * (a[3] * a[4] * a[5] * a[6] * ……)
b[3] = (a[0] * a[1] * a[2]) * (a[4] * a[5] * a[6] * ……)
b[4] = (a[0] * a[1] * a[2] * a[3]) * (a[5] * a[6] * ……)
b[5] = (a[0] * a[1] * a[2] * a[3] * a[4]) * (a[6] * ……)
……
观察以上式子,可以发现:
这里写图片描述
b数组中的每一个元素就是a数组的一个前缀积乘以一个后缀积,所以预处理出a数组的前缀积以及后缀积即可O(n)求出b数组
【AC代码】:

/**
 * Return an array of size *returnSize.
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* productExceptSelf(int* nums, int numsSize, int* returnSize) {
    int * res = (int *)malloc(sizeof(int) * numsSize);
    res[0] = res[1] = nums[0];
    for(int i = 2; i < numsSize; i++){
        res[i] = res[i - 1] * nums[i - 1];
    }
    int index = numsSize - 1;
    int temp_pro = nums[index--];
    for(int i = numsSize - 2; i >= 1; i--){
        res[i] *= temp_pro;
        temp_pro *= nums[index--];
    }
    res[0] = temp_pro;
    *(returnSize) = numsSize;
    return res;
}
FPGA之串口收发字符串之(四)——串口屏USART_HMI介绍 之前对串口各模块的设计都做了相关介绍。这里介绍串口屏的相关知识。 本次项目使用的串口屏型号是陶晶驰串口屏TJC3224T024_011,这个型号的串口屏的资料在官网可以找到。本文抛转引玉,简单介绍以便在本工程中更好的应用。 下图是该串口屏的实物图: 一般地,使用单片机或者嵌入式MCU控制串口屏,都会用到串口,同样地,在FPGA中实现也是类似,不过稍微复杂,具体代码设计过程中有以下问题需要... 阅读详情

相关推荐

从Delta Delay到Timing Window:详解数字芯片后端时序差异的那些坑

本文深入剖析了数字芯片后端设计中,模块级与系统级时序分析结果不一致的核心原因。重点解释了Delta Delay如何导致模块级分析的乐观假设,以及Timing Window(时序窗口)差异如何通过影响串扰噪声计算,在顶层集成时引发新的时序违例,尤其是保持时间问题。文章为工程师提供了从约束建模到签核策略的系统性应对方案。

beer8的博客 506

[LeetCode] Plus One - 整数字符转换相加

题目概述:Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list...

weixin_34088583的博客 278

ENVI学习总结(十二)——基于改进的 CASA 模型反演 NPP

基于改进的 CASA 模型反演 NPP 数据为地理空间数据云提供的 TM 影像,其具体信息如图 1 所示。该实验中所使用的 TM 数据已进行过 QUAC 快速大气校正,来消除大气和光照等因素对地物反射的影响。Landsat 主题成像仪(TM)是 Landsat4 和 Landsat5 携带的传感器,每 16 天扫描同一地区,即 16 天覆盖全球一次。 TM 影像包含 7 个波段,波段 1-5 ...

Arcgiser的博客 3万+

《leetCode》:3Sum

题目Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: Elements in a triplet (a,b,c) must be

wojiushimogui的博客 1426

YOLOv5添加注意力机制的具体步骤

本文主要介绍了 本文在此篇博客的基础上向YOLOv5-5.0版 本文主要包括以下内容一、CBAM注意力机制添加(1)修改yolov5s主干网络(2)在common.py中添加可调用的CBAM模块(3)向yolo.py文件添加CBAMC3判断语句二、SE注意力机制添加 本文以yolov5s网络为例 一、CBAM注意力机制添加 注意力机制可以添加在backbone,Neck,Head等部分,接下来本文以backbone主干网络为例 (1)修改yolov5s主干网络 1.在yolov5-5.0工程文件夹下,找到m

thy0000的博客 2万+

项目管理-(补充)七种基本质量工具

七种基本质量工具,用于PDCA循环的架构内 解决与质量相关的问题,分为老七工具和新七工具。 1)老七种:刘英只点劣质茶(流程图、因果图、直方图、散点图、帕累托图、控制图、核查表)2)新七种:锯树联亲测动优(矩阵图、树形图、关联图、亲和图、过程决策程序图、活动网络图、优先矩阵)

weixin_42081167的博客 4616

LeetCode 905. Sort Array By Parity (C++ C JAVA Python3 实现)

905. Sort Array By Parity Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array ...

帽帽的博客 908

实战对比:VINS和ORBSLAM3在无人机避障中的表现(含实测数据)

本文通过实战测试,深度对比了VINS和ORBSLAM3两种主流视觉SLAM算法在无人机避障中的表现。测试聚焦于光照变化、动态遮挡和快速运动三大挑战,提供了详细的实测数据与性能分析。结果表明,VINS在计算效率和实时性上占优,而ORBSLAM3在定位精度和地图管理方面更稳健,为不同应用场景下的工程选型提供了清晰依据。

醉三国 633

返回二叉树的前序遍历(非递归实现)

题目描述: 分析:本题目需要借助于栈实现(栈用数组实现,其中元素类型是二叉树结点的指针,即TreeNode*,因为我们从栈顶取出元素时,要找到其右子树)。从根结点开始,访问左路节点,并依次将访问过的结点入栈,直到左路结点访问完。然后依次访问栈顶元素的右子树(模拟子问题)。 在C语言中,自己得先实现栈,以及栈的部分接口。另外由于我们事先不知道二叉树有多少个结点,因此还得先遍历一遍求出结...

lyl194458的博客 455

别再纠结了!手把手教你根据项目需求选对目标检测框架(MMDetection/Detectron2/YOLOv8实战对比)

本文详细对比了三大目标检测框架MMDetection、Detectron2和YOLOv8的适用场景与实战技巧,帮助开发者根据项目需求精准选型。从毕业设计到工业落地,分析不同场景下的核心需求与框架优势,提供决策树和避坑指南,确保技术选型与项目目标高度匹配。

weixin_30342209的博客 560

18. 从 SAP Fiori Elements List Report 中的图片显示,谈谈背后的 XML Template 设计机制

至此,Fiori Elements List Report 这个模版里,图片显示的原理,笔者已经从开发人员层面需要定义的注解,和 Fiori Elements 框架层面如何解析这些注解,这两方面做了深入介绍。从本文开始,我们从 Fiori Elements 预制的标准 XML Template 模版的设计,来介绍我们在最终 Fiori Elements 页面看到的产品图标,是如何渲染出来的。但是,List Report 里产品的图标显示,到底是上面这些 XML 文件里的哪一个里定义的呢?

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 617

Leetcode-167. Two Sum II - Input array is sorted c语言

1、题目:点击打开链接 2、下面代码是暴力破解,超时无法通过: /** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */ int* twoSum(int* numbers, int numbersSize,

0_o_c 1483

LightGBM之LGBMRegressor()参数详解以及调参

LightGBMLight Gradient Boosting Machine)是一种梯度提升框架,它使用决策树作为基学习器。LightGBM 可以说是在 XGBoost 上做的优化。LightGBM 为高效并行计算而生,它的 Light 体现在以下几个点上:更快的训练速度更低的内存使用支持单机多线程,多机并行计算,以及 GPU 训练能够处理大规模数据。

我走的每一步都算数 3756

LeetCode 238: Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n).

哈哈的个人专栏 4263

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

leetcode 238: Product of Array Except Self

leetcode 238: Product of Array Except Self python, c++ java

西施豆腐渣 1万+

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

LeetCode:238. Product of Array Except Self

LeetCode:238. Product of Array Except Self Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums...

Wisimer 229

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

LeetCode 238: Product of Array Except Self

LeetCode 238: Product of Array Except Self 题目描述 给定一个数组 A[0, 1,..., n-1],请构建一个数组 B[0, 1,..., n-1],其中 B 中的元素 B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。要求不能使用除法。 解题思路 在O(N)时间复杂度下,分别进行自左向右、自右向左两次累乘即...

HakunaMatata的博客 185

LeetCode238:Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements ofnums except nums[i]. Solve it without division and in O(

1319

LeetCode: 238. Product of Array Except Self

LeetCode: 238. Product of Array Except Self 题目描述 Given an array nums of n integers where n &gt; 1, return an array output such that output[i] is equal to the product of all the elements of nums excep...

杨领well的专栏 185

LeetCode238:Product of Array Except Self

Given an arraynumsofnintegers wheren> 1, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i]. Example: Input: [1,2,3,4] Output: ...

卷卷萌的博客 219

LeetCode 238:Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O

judadeshu的博客 293

LeetCode:238product of Array Except Self

problem Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. solution 初始想法,设立一个等长的数组用来存储返...

erzhushashade的博客 133

leetcode:238. Product of Array Except Self(Java)解答

转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Product of Array Except SelfGiven an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of

z_zhaojun的博客 1953

Leetcode: 238. Product of Array Except Self

Question Given an array numsof n integers where n > 1, return an array output such that output[i]is equal to the product of all the elements of numsexcept nums[i]. Example: Input: [1,2,3,4] Outp...

兔子窝 140

LeetCode笔记:238. Product of Array Except Self

计算除了该元素以外所有元素的乘积

Minecraft 995

LeetCode解题分享:238. Product of Array Except Self

Problem Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Example: Input: [1,2,3,4] Ou...

DaVinciL的博客 267
上一篇: Leetcode 258:Add Digits
下一篇: Leetcode 237:Delete Node in a Linked List
Code_J_xer
博客等级 码龄11年 12粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值