Description:

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[] res = new int[nums.length];
res[nums.length - 1] = 1;
for(int i=res.length-2; i>=0; i--) {
res[i] = nums[i+1] * res[i+1];
} int l = 1;
for(int i=0; i<nums.length; i++) {
res[i] *= l;
l *= nums[i];
} return res;
}
}

最新文章

  1. Linux 驱动学习笔记05--字符驱动实例,实现一个共享内存设备的驱动
  2. SpringMvc xml 配置
  3. [CF442C] Artem and Array (贪心+单调栈优化)
  4. url中文参数解决方案
  5. 1190: [HNOI2007]梦幻岛宝珠 - BZOJ
  6. Android PagerAdapter
  7. MVC5学习笔记
  8. ZOJ 3872 Beauty of Array DP 15年浙江省赛D题
  9. ubuntu下mysql二进制包安装
  10. IIS7出现“HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。”错误-Windows-
  11. hibernate动态切换数据源
  12. Linux 重启命令
  13. Android Studio设置字体和主题
  14. ReactiveSwift源码解析(三) Signal代码的基本实现
  15. ASP.NET Web API决跨域问题
  16. ERROR:scala:Error:Object scala.runtime in compiler mirror not found
  17. flask+mako+peewee(上)
  18. Why there is two completely different version of Reverse for List and IEnumerable?
  19. 百度搜索引擎取真实地址-python代码
  20. js中对String去空格

热门文章

  1. VC++中动态链接库的显示加载和隐式加载的区别
  2. swd 适配器接口线序
  3. Drupal模块的安装方法
  4. CSS3加载动画
  5. 【转】WCF入门教程六[一个简单的Demo]
  6. 第二百九十一节,RabbitMQ多设备消息队列-安装与简介
  7. linux -- Ubuntu 命令技巧合集
  8. CentOS下的一些基础问题解答
  9. C# HttpClientHelper请求
  10. [转]Git学习笔记与IntelliJ IDEA整合