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] * ...
随机推荐
- 更丰富的符号工具包 Font Awesome
我时常想要在此类文档中通过一些图形符号来表达更丰富的含义或是对段落进行标注,例如使用 Emoji.然而 Emoji 在这方面仍然有存在一些不足,如: 颜色与文字风格不统一, 在不同系统的平台上显示不统 ...
- 基于Centos7+Flask+Nginx+uWSGI+Python3的服务器网页搭建教程
之前完成了贴吧签到系统的搭建,笔者想将这个功能分享给更多人使用,所以尝试搭建了一个网页,一路遇到了很多问题,最终解决了,记录下过程分享给大家 首先安装 uWSGI ,和 Nginx 配套使用,具体用途 ...
- LeetCode 1079. Letter Tile Possibilities
原题链接在这里:https://leetcode.com/problems/letter-tile-possibilities/ 题目: You have a set of tiles, where ...
- vant - Navbar slot 插槽使用
//子组件 <template> <van-nav-bar> <slot slot="left" name="left">& ...
- 【JOISC2018|2019】【20190622】mergers
题目 一\(n\)个节点的树,节点被分成\(k\)个集合,\(i\)属于\(S_i\), 一条边是可划分的当且仅当左右两边的子树不存在相同集合的点 你一次可以合并两个集合,求最少的操作次数使得所有边都 ...
- shell 查看目前机器listen的所有端口
netstat -lnp 这条命令的意思是列出系统里面监听网络连接的端口号和相应的进程PID.参数说明:-t:表示列出TCP连接(也可以加上-u参数表示同时列出UDP网络连接)-l:表示列出正在网络监 ...
- mysql 修改表名
//重命名表 rename table table1 to table2; //重命名多个表 rename table table1 to table2,table3 to table4,table5 ...
- 「2019-8-11提高模拟赛」女装盛宴 (flag)
传送门 Solution 基环树+倍增+双指针 第一次因为#define int long long而玄学RE 为什么标程都不用开\(long long\)啊 Code /*玄学RE 看来defi ...
- [JLOI 2015]骗我呢
传送门 Description 求给\(n*m\)的矩阵填数的方案数 满足: \[ 1\leq x_{i,j}\leq m \] \[ x_{i,j}<x_{i,j+1} \] \[ x_{i, ...
- eclipse juno 怎么安装maven
步骤如下: 1.下载maven的bin,在apache官方网站可以下载. 2.下载下来之后,解压,找个路径放进去, 把bin的位置设在环境变量里,新建环境变量MAVEN_HOME. 3.在PATH里加 ...