LeetCode 238. Product of Array Except Self
来源:互联网 发布:php image not loaded 编辑:程序博客网 时间:2024/06/12 00:26
解题思路:l两个循环,第一个从0到i-1,累乘,第二个从n到i+1,累乘.
class Solution {public: vector<int> productExceptSelf(vector<int>& nums) { int N = nums.size(); vector<int> res(N,1); for(int i=0; i<N; i++){ if (i==0) res[i] = 1; else res[i] = res[i-1]*nums[i-1]; } int tmp = 1; for(int i=N-1; i>=0; i--){ res[i] *= tmp; tmp *= nums[i]; } return res;}};
0 0
- [leetcode] 238.Product of Array Except Self
- [LeetCode]238.Product of Array Except Self
- [leetcode] 238. Product of Array Except Self
- Leetcode 238. Product of Array Except Self
- [LeetCode]238. Product of Array Except Self
- 238. Product of Array Except Self LeetCode
- LeetCode 238. Product of Array Except Self
- [LeetCode]238. Product of Array Except Self
- LeetCode *** 238. Product of Array Except Self
- LeetCode 238. Product of Array Except Self
- 【leetcode】238. Product of Array Except Self
- leetcode-238. Product of Array Except Self
- Leetcode 238. Product of Array Except Self
- 【leetcode】238. Product of Array Except Self
- LeetCode- 238. Product of Array Except Self
- leetcode 238. Product of Array Except Self
- 【leetcode】238. Product of Array Except Self
- leetcode:238. Product of Array Except Self
- 纯代码给WordPress网站添加独立下载页面功能
- 详细图解MySQL(win7x64 5.7.16版本)下载、安装、配置与使用
- sql语句在遇到字符串的时候,使用单引号
- ℃江让您从精通到入门:App登陆模块的实现
- java 调用mvel; 文件或字符串
- LeetCode 238. Product of Array Except Self
- WordPress下载管理插件:Hacklog-downloadmanager
- 如何破解12位+字符的高强度密码?
- 关键字declare的使用
- 对称加密算法
- POJ 2253 Frogger
- VIM
- 在PowerDesigner中创建数据库物理模型
- 人工智能时代的降临