博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Product of Array Except Self
阅读量:4318 次
发布时间:2019-06-06

本文共 803 字,大约阅读时间需要 2 分钟。

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.)

class Solution {public:    vector
productExceptSelf(vector
& nums) { int numsSize = nums.size(); vector
res(numsSize,1); for(int i=1;i
=0;i--){ res[i] = res[i]*tmp; tmp *= nums[i]; } return res; }};

 

转载于:https://www.cnblogs.com/zengzy/p/5003043.html

你可能感兴趣的文章
深入.NET框架与面向对象的回顾
查看>>
merge http://www.cplusplus.com/reference/algorithm/merge/
查看>>
Python-DB接口规范
查看>>
改变label中的某字体颜色
查看>>
[转]SQL SERVER 的排序规则
查看>>
SQLServer锁原理和锁的类型
查看>>
Eclipse中SVN的安装步骤(两种)和使用方法[转载]
查看>>
C语言函数的可变参数列表
查看>>
七牛云存储之应用视频上传系统开心得
查看>>
struts2日期类型转换
查看>>
Spark2-数据探索
查看>>
大数据初入门
查看>>
Java学习笔记-类型初始化
查看>>
设计模式原则之单一职责原则
查看>>
Android:日常学习笔记(10)———使用LitePal操作数据库
查看>>
鱼那么信任水,水却煮了鱼
查看>>
HTML5 Canvas ( 文字的度量 ) measureText
查看>>
Http和Socket连接区别
查看>>
Arrays基本使用
查看>>
受限玻尔兹曼基
查看>>