238. Product of Array Except Self(Java)
来源:互联网 发布:什么是java系统类库 编辑:程序博客网 时间:2024/06/05 09:01
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].
Follow up:
Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)
public class Solution { public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] res = new int[n]; res[0] = 1; for (int i = 1; i < n; i ++) res[i] = res[i - 1] * nums[i - 1]; int right = 1; for (int i = n - 1; i >= 0; i --) { res[i] *= right; right *= nums[i]; } return res; }}
阅读全文
0 0
- 238. Product of Array Except Self(Java)
- [letecode java] Product of Array Except Self
- (java) Product of Array Except Self
- leetcode:238. Product of Array Except Self(Java)解答
- 【Leetcode】:238. Product of Array Except Self 问题 in JAVA
- leetcode-java-238. Product of Array Except Self
- [leetcode]238. Product of Array Except Self -- Java 代码
- [leetcode] 238.Product of Array Except Self
- [LeetCode]238.Product of Array Except Self
- [leetcode] 238. Product of Array Except Self
- Leetcode 238. Product of Array Except Self
- [LeetCode]238. Product of Array Except Self
- 238. Product of Array Except Self LeetCode
- LeetCode 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- Spring-@Autowired注解、@Resource注解和@Service注解
- Java消息中间件--JMS规范
- 3523. 【NOIP2013模拟11.7A组】JIH的玩偶(tree)
- Spotlight on Unix 监控Linux服务器的安装与使用
- Spring的七大模块,以及每个模块的作用
- 238. Product of Array Except Self(Java)
- 条码控件Dynamsoft Barcode Reader教程:从PDF417驾驶执照中提取数据
- 三、rabbitMQ helloWorld入门程序
- https://vuejs.org/v2/examples/svg.html
- CS20SI Tensorflow for Deeplearning课程笔记(四) word2vec with NCE loss and visualize the embeddings
- 数据类型转换
- POJ.Find The Multiple
- D
- 在CentOS7上安装RabbitMQ