Leetcode 238. Product of Array Except Self
採用動態規劃的思想
class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
vector<int>re(nums.size(),1);
vector<int>left(re);
int right=1;
for(int i=1; i<nums.size(); ++i)
{
left[i]=left[i-1]*nums[i-1];
}
for(int i=nums.size()-2; i>=0; --i)
{
right*= nums[i+1];
re[i]=left[i]* right;
}
re.back()=left.back();
return re;
}
};
相關文章
- [LeetCode] 238. Product of Array Except SelfLeetCode
- LeetCode:Product of Array Except SelfLeetCode
- LeetCode C++ 1464. Maximum Product of Two Elements in an Array【Array/Sort】簡單LeetCodeC++
- Leetcode Maximum Product SubarrayLeetCode
- Leetcode: Self CrossingLeetCodeROS
- Leetcode - Self CrossingLeetCodeROS
- Leetcode-Maximum Product SubarrayLeetCode
- LeetCode-Self CrossingLeetCodeROS
- LeetCode 238. 除自身以外陣列的乘積LeetCode陣列
- LeetCode-Maximum Product of Word LengthsLeetCode
- [leetCode][001] Maximum Product SubarrayLeetCode
- Leetcode Sort ArrayLeetCode
- LeetCode | 152. Maximum Product SubarrayLeetCode
- Rotate Array@LeetCodeLeetCode
- Leetcode - Patching ArrayLeetCode
- LeetCode-Rotate ArrayLeetCode
- LeetCode-Shuffle an ArrayLeetCode
- 【LeetCode】Self Crossing(335)LeetCodeROS
- [LeetCode/LintCode] Largest Palindrome ProductLeetCode
- LeetCode-Pathcing ArrayLeetCode
- Leetcode Search in Rotated Sorted ArrayLeetCode
- Leetcode Merge Sorted ArrayLeetCode
- leetcode刷題--Rotate ArrayLeetCode
- LeetCode Kth Largest Element in an ArrayLeetCode
- Leetcode 33 Search in Rotated Sorted ArrayLeetCode
- Leetcode Search in Rotated Sorted Array IILeetCode
- leetcode Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode-Merge Sorted ArrayLeetCode
- Leetcode-Search in Rotated Sorted ArrayLeetCode
- Search in Rotated Sorted Array leetcode javaLeetCodeJava
- LeetCode Patching Array All In OneLeetCode
- LeetCode之Squares of a Sorted Array(Kotlin)LeetCodeKotlin
- LeetCode Shuffle an Array(打亂陣列)LeetCode陣列
- [LeetCode] 852. Peak Index in a Mountain ArrayLeetCodeIndexAI
- LeetCode之Sort Array By Parity(Kotlin)LeetCodeKotlin
- Leetcode 26 Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode 442. Find All Duplicates in an ArrayLeetCode
- Leetcode 88. Merge Sorted ArrayLeetCode