I have been solving problem(Product of Array Except Self) on leetcode.
My code compile successfully and passed 18 out of 19 test cases. I try to figure out the failed test case but no luck.
Exception: Time Limit Exceeded
Input: https://leetcode.com/submissions/detail/439297112/testcase/ - (70000 integers)
My Code
public int[] productExceptSelf(int[] nums) {
int arr[] = { 1, 2, 3, 4 };
return mySolution(arr);
}
public static int[] mySolution(int arr[]) {
int size = arr.length;
int j;
int product;
int[] result = new int[size];
for (int i = 0; i < size; i++) {
j = 0;
product = 1;
while (j < size) {
if (j == i) {
j++;
continue;
}
product *= arr[j];
j++;
}
result [i] = product;
}
return result;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…