[LeetCode] Product of Array Except Self
LeetCode of Array product self except
2023-09-14 09:01:04 时间
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
LeetCode 318. Maximum Product of Word Lengths 给定一个字符串数组 words,找到 length(word[i]) * length(word[j]) 的最大值,并且这两个单词不含有公共字母。你可以认为每个单词只包含小写字母。如果不存在这样的两个单词,返回 0。
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.)
两次遍历,第一次遍历,将0到i-1的乘积放入res[i];第二次遍历,记录i+1到len-1的乘积,再与左边的乘积相乘,得到最终结果放入res[i]。
LeetCode 318. Maximum Product of Word Lengths 给定一个字符串数组 words,找到 length(word[i]) * length(word[j]) 的最大值,并且这两个单词不含有公共字母。你可以认为每个单词只包含小写字母。如果不存在这样的两个单词,返回 0。
相关文章
- Java实现 LeetCode 452 用最少数量的箭引爆气球
- SQL Server实现 LeetCode 176 第二高的薪水
- Java实现 LeetCode 90 子集 II(二)
- Java实现 LeetCode 43 字符串相乘
- Java实现 LeetCode 20 有效的括号
- Java实现LeetCode 111. Minimum Depth of Binary Tree
- (LeetCode 153)Find Minimum in Rotated Sorted Array
- [LeetCode] Best Time to Buy and Sell Stock
- LeetCode - 209 长度最小的子数组
- 【LeetCode 简单 树 python3】543. 二叉树的直径
- Leetcode 884. 两句话中的不常见单词
- leetcode 572. Subtree of Another Tree
- leetcode 191. Number of 1 Bits
- leetcode 447. Number of Boomerangs
- leetcode 697. Degree of an Array
- leetcode 695. Max Area of Island
- leetcode 104. Maximum Depth of Binary Tree
- 【Leetcode刷题Python】138. 复制带随机指针的链表