238. 자기 자신을 제외한 배열의 곱 | LeetCode | Top Interview 150 | 코딩 질문
발행: (2025년 12월 18일 오전 06:36 GMT+9)
1 min read
원문: Dev.to
Source: Dev.to
문제 링크
https://leetcode.com/problems/product-of-array-except-self/
해결책
class Solution {
public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] left = new int[n];
int[] right = new int[n];
left[0] = 1;
for (int i = 1; i = 0; i--) {
right[i] = right[i + 1] * nums[i + 1];
}
int[] ans = new int[n];
for (int i = 0; i < n; i++) {
ans[i] = left[i] * right[i];
}
return ans;
}
} 