238. Product of Array Except Self
659 ワード
class Solution {
public int[] productExceptSelf(int[] nums) {
int[] result = new int[nums.length];
result[0] = 1;
for (int i = 1; i < nums.length; i++) {
result[i] = result[i-1] * nums[i - 1];
}
int right = 1;
for (int i = nums.length - 1; i >= 0; i--) {
result[i] *= right;
right *= nums[i];
}
return result;
}
}
Runtime: 1 ms, faster than 100.00% of Java online submissions for Product of Array Except Self.Memory Usage: 49.5 MB, less than 82.92% of Java online submissions for Product of Array Except Self.
以前やったことがある
Reference
この問題について(238. Product of Array Except Self), 我々は、より多くの情報をここで見つけました https://velog.io/@jwade/238.-Product-of-Array-Except-Selfテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol