Product of Array Except Self
来源:互联网 发布:电脑淘宝登录不了 编辑:程序博客网 时间:2024/05/21 15:41
这道题还有更精妙的解法,不过现在我们先采用这个最标准的O(n)做法了。
先从左往右一遍,再从右往左一遍。
public class Solution { public int[] productExceptSelf(int[] nums) { int[] result = new int[nums.length]; result[0] = 1; for (int i = 1; i < nums.length; i++) { result[i] = result[i - 1] * nums[i - 1]; } int right = 1; for (int i = nums.length - 1; i >= 1; i--) { result[i] = result[i] * right; right = right * nums[i]; } result[0] = right; return result; }}
0 0
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- linux grep通过管道输出到head出现write error: Broken pipe错误
- Jsp中EL表达式
- 几台电脑同时使用一个无线路由器上网,外部ip相同,各个电脑内部ip不同,路由器如何区分某个数据包是发给某个电脑的?
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- leetcode 88. Merge Sorted Array
- Product of Array Except Self
- Android 中ViewPager 实现banner无限轮播效果
- 客户端和服务器端的区别
- Android源码适配器模式---Activity类结构
- python以post方式登录csdn网站,并以cookie方式访问个人信息
- leetcode记录 31-60
- android 自定义控件实现流式布局
- 部分RTMP协议的电视台直播地址
- how to compile neovim