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. python之ftplib库

    检测ftp是否可用 #!/usr/bin/python #coding:utf-8 from ftplib import FTP def ftp_open(ip,user,passwd): try: ...

  2. shell-IF判断

    #!/bin/bash echo "-----------------strat---------------" read -p "Enter a number:&quo ...

  3. 6.24 AppCan移动开发者大会:议程重大更新,报名即将关闭

    大会倒计时2天,议程重大更新,报名通道即将关闭! 创业6年,由AppCan主办的第一届移动开发者大会将在本周五盛大召开.超过100万开发者线上参与.现场1500人规模.50家移动互联企业深度参与.30 ...

  4. hdu 1880 魔咒词典

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1880 魔咒词典 Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有10 ...

  5. System.IO之内存映射文件共享内存

    内存映射文件是利用虚拟内存把文件映射到进程的地址空间中去,在此之后进程操作文件,就 像操作进程空间里的地址一样了,比如使用c语言的memcpy等内存操作的函数.这种方法能够很好的应用在需要频繁处理一个 ...

  6. 44.do文件格式

    style1: transcript onif {[file exists rtl_work]} {<span style="white-space:pre"> < ...

  7. GitFlow教程

    GitFlow教程 这份教程是博主学到的git基础,仅适合小团队使用,仅供参考 配置Git 配置github上面的账号,首先需要自己在git上注册一个账号 git config --global us ...

  8. python关于字典的使用方法

    #-*- coding:utf-8 -*-#Author:gxli#定义字典id_db={ 233333199211222342:{ 'name':'xiaoa', 'age':23, 'addr': ...

  9. mac下phpstorm左侧的project列表找不到了

    早上开机,发现左侧的project列表没有了,用着不方便,当然了,是可以调出来的. View-Tool Windows-Project,就出来来. 快捷键:command+1. 问题解决.

  10. Mysql 慢查询设置

    Mysql慢查询设置 分析MySQL语句查询性能的方法除了使用 EXPLAIN 输出执行计划,还可以让MySQL记录下查询超过指定时间的语句,我们将超过指定时间的SQL语句查询称为“慢查询”. === ...