Files
obsidian/АиСД/Задачи/LeetCode/Product of Array Except Self.md
roma-dxunvrs 0e6e583e6d
deploy / Pull and Restart (push) Successful in 17s
refactor: wiki links -> md links
2026-09-22 08:52:23 +03:00

23 lines
625 B
Markdown

Leetcode #238 | #Medium | [Префикс](../../Методы/Префикс.md)
## Идея
Префиксные и суффиксные произведения
## Big-O
- Время ```O(N)```
- Память ```O(1)```
## Код
```Java
class Solution {
public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] res = new int[n];
res[0] = 1;
for (int i = 1; i < n; i++) res[i] = res[i - 1] * nums[i - 1];
int right = 1;
for (int i = n - 1; i >= 0; i--) {
res[i] *= right;
right *= nums[i];
}
return res;
}
}
```