Given an array arr[] of n integers, construct a Product Array prod[] (of same size) such that prod[i] is equal to the product of all the elements of arr[] except arr[i]. Solve it without division operator and in O(n).

Example:
arr[] = {10, 3, 5, 6, 2}
prod[] = {180, 600, 360, 300, 900}

     public static int[] selfExcluding(int[] input){
if(input == null || input.length == 0) return null;
int len = input.length;
int[] output = new int[len];
for(int i = 0; i < len; i ++){
output[i] = 1;
}
int left = 1, right = 1;
for(int i = 1; i < input.length; i ++){
left *= input[i - 1];
output[i] *= left;
right *= input[len - i];
output[len - i - 1] *= right;
}
return output;
}

A Product Array Puzzle的更多相关文章

  1. ASP.NET MVC——Razor视图引擎

    Razor是MVC框架视图引擎,我们今天就来说一说Razor视图引擎. 首先还是来创建一个基础项目叫Razor来演示. 先来定义一个Model叫Product public class Product ...

  2. 《精通MVC5.0》笔记Razor

    1.1.视图声明数据类型 Razor声明都是@开始,例如@model MVC.Models.Product声明了控制器创给视图的数据类型,这样就可以在视图使用@Modle.property访问数据,如 ...

  3. NumPy的详细教程

    原文  http://blog.csdn.net/lsjseu/article/details/20359201 主题 NumPy 先决条件 在阅读这个教程之前,你多少需要知道点python.如果你想 ...

  4. 【MVC 4】2.使用 Razor

    作者:[美]Adam Freeman      来源:<精通ASP.NET MVC 4> Razor 是微软 MVC3 引入的视图引擎的名称,并在MVC 4 中进行了修订.视图引擎处理 A ...

  5. C# 自定义集合

    自定义类型 public class Product { public int Id { get; set; } // 自增ID public string Name { get; set; } // ...

  6. Linq常用查询运算符

    Linq一共包含五十几个查询运算符,常用的根据类型来区分一共有5类左右,这五类里面一些事在项目查询中经常用到的.不过linq运算符的命名十分规范,基本从字面意思就能猜测出来是干嘛用的,下面我们挑选一些 ...

  7. 探究foreach对于迭代变量的封装性的研究

    众所周知教科书上对于foreach之中的注释是在遍历过程中无法改变其遍历的元素例如声明一个数组 ,,,}; foreach(int m in ii){ m = ;//错误 “m”是一个“foreach ...

  8. VSTO学习笔记(十四)Excel数据透视表与PowerPivot

    原文:VSTO学习笔记(十四)Excel数据透视表与PowerPivot 近期公司内部在做一种通用查询报表,方便人力资源分析.统计数据.由于之前公司系统中有一个类似的查询使用Excel数据透视表完成的 ...

  9. Pro Aspnet MVC 4读书笔记(4) - Working with Razor

    Listing 5-1. Creating a Simple Domain Model Class using System; using System.Collections.Generic; us ...

随机推荐

  1. vagrant

    puppet chef ansible salt docker https://github.com/ansible/ansiblehttps://github.com/saltstack/salth ...

  2. DrawTool多重笔之前奏 => 通过InkAnalyzer实现图形识别

    这里要介绍的是通过InkAnalyzer来实现简单图形的识别,例如圆,椭圆,正方形,三角形等,当然你也可以通过扩展来实现自定义图形的识别,在使用InkAnalyzer前,你需要引用IAWinFX.dl ...

  3. 使用eclipse开发

    Eclipse下载地址:http://www.eclipse.org/ 下载后进行解压缩,点击eclipse.exe即可使用eclipse workspace:工作区      Project:项目 ...

  4. 苏泊尔借助微软CRM提升客户满意度

    企业背景 作为中国最大.全球第二的炊具研发制造商和中国小家电领先品牌,品质和创新一是苏泊尔矢志追求的企业理念,从火红点无油烟锅的发明到能做柴火饭的球釜IH饭煲的面世,苏泊尔用产品的创新和品质的承诺,不 ...

  5. hdu 1316 How Many Fibs?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...

  6. linux安装R语言

    系统:centos 6.4  64bit 安装可以使用rpm包安装,也可以用源码安装. 但是rpm安装,各种依赖比较麻烦.所以我采用源码安装. 下载:http://www.r-project.org/ ...

  7. SQLite之读取数据库内容

    1.打开已有数据库. //打开数据库 - (BOOL )openDB {// 红色部分修改为自己的数据库路径 return (SQLITE_OK == sqlite3_open([@"/Us ...

  8. ExtJS MVC学习手记

    开始学习ExtJS的MVC了.这篇文章仅是用来做一个目录,为自己这个阶段的学习内容做个索引. 手记涉及的文章: EXTJS MVC结构(译自ExtJS4.0文档中的<MVC Architectu ...

  9. java implement

    接口不能被实例化,但是可以声明一个接口类型的变量. eg. A implements B,则可以有B variableName = new A(),这和extends的用法是类似的 接口可被认为是纯抽 ...

  10. Java Day 10

    接口应用 多态 猫 x = new 猫(); 动物 x = new 猫();  父类或接口的引用指向其子类的对象 class BookPC{ public static void main(Strin ...