LeetCode 238. 除自身以外数组的乘积(Product of Array Except Self)
238. 除自身以外数组的乘积
238. Product of Array Except Self
题目描述
LeetCode238. Product of Array Except Self中等
Java 实现
class Solution {
public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] before = new int[n], after = new int[n], res = new int[n];
before[0] = 1;
after[n - 1] = 1;
for (int i = 1; i < n; i++) {
before[i] = before[i - 1] * nums[i - 1];
}
for (int i = n - 2; i >= 0; i--) {
after[i] = after[i + 1] * nums[i + 1];
}
for (int i = 0; i < n; i++) {
res[i] = after[i] * before[i];
}
return res;
}
}
相似题目
参考资料
- https://leetcode.com/problems/product-of-array-except-self/
- https://leetcode-cn.com/problems/product-of-array-except-self/
LeetCode 238. 除自身以外数组的乘积(Product of Array Except Self)的更多相关文章
- Java实现 LeetCode 238 除自身以外数组的乘积
238. 除自身以外数组的乘积 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元 ...
- [leetcode]238. 除自身以外数组的乘积
题目描述 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输 ...
- LeetCode 238. 除自身以外数组的乘积( Product of Array Except Self)
题目描述 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输 ...
- [LeetCode] 238. 除自身以外数组的乘积 ☆☆☆(左积*右积)
描述 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输入: ...
- leetcode 238. 除自身以外数组的乘积 (python)
给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输入: [1 ...
- [Swift]LeetCode238. 除自身以外数组的乘积 | Product of Array Except Self
Given an array nums of n integers where n > 1, return an array outputsuch that output[i] is equa ...
- Leetcode题目238.除自身以外数组的乘积(中等)
题目描述: 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: ...
- leecode 238除自身以外数组的乘积
class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { //用除法必须要 ...
- 剑指offer 66. 构建乘积数组(Leetcode 238. Product of Array Except Self)
剑指offer 66. 构建乘积数组 题目: 给定一个数组A[0, 1, ..., n-1],请构建一个数组B[0, 1, ..., n-1],其中B中的元素B[i] = A[0] * A[1] * ...
随机推荐
- msdtc不可用
在使用“经销商园地 网上订单处理程序”等程序时,如果程序报:服务器×××上的MSDTC不可用”,可以按照以下方法进行解决: 在windows控制面版-->管理工具-->服务-->Di ...
- JSON和计算机网络的个人总结
JSON JSON是什么? JSON:JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式.它基于ECMAScript (欧洲计算机协会制定的js规范) ...
- A Class of Blind Source Extraction Method Using Second-Order Statistics
基于二阶统计量的盲源提取方法[1]. 文中提出了一系列基于二阶统计量的算法,包括离线BSE和在线BSE算法,可以提取平稳信号和非平稳信号.这些算法中,通过挖掘信号特征,提出了新的打分函数,以及一个无参 ...
- 使用terraform 进行gitlab 代码仓库批量迁移
gitlab 的代码是在文件目录中,这个对于批量迁移很简单,只需要copy 文件夹(但是对于不同gitlab server 可能需要重新设置目录权限) 几个问题 大批量仓库tf resource问 ...
- 杂乱的Solidity - 2019-7-13
要清楚在区块链上开发DApp的架构[x][][][][][] DApp是去中心化的应用 基于智能合约 去中心化的游戏规则 代币激励
- 移动端tap事件(轻击、轻触)
一.问题 ①移动端也有click点击事件,click点击会延迟200~300ms ②因为点击的响应过慢,影响了用户体验,所以需要解决响应慢的问题 二.解决方案 ①使用tap事件:即轻击,轻敲,响应速度 ...
- 如何学习uni-app?
uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架. 开发者通过编写 Vue.js 代码,uni-app 将其编译到iOS.Android.微信小程序.H5等多个平台,保证其正确运行并 ...
- 记录一次SpringBoot实现AOP编程
需求 最近碰到一个问题,需要对关键操作的入参和返回值进行记录,并不是使用log记录,而是插入到数据库中. 思路:如果采用硬编码,在每个操作后都添加,会产生大量重复代码.因而打算使用自定义注解,通过AO ...
- centos7---mysql5.7主从复制读写分离
1 分别在两台centos 7系统上安装mysql 5.7 具体的安装步骤可以见此链接,https://blog.csdn.net/qq_15092079/article/details/816292 ...
- html 获取项目根路径
html 获取项目根路径 function getContextPath(){ var pathName = document.location.pathname; //当前文件的绝度路径 var i ...