Created
January 4, 2016 20:57
-
-
Save Magdi/b99caa6f07163995f202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int[] productExceptSelf(int[] nums) { | |
int n = nums.length; | |
int[] left = new int[n], right = new int[n], arr = new int[n]; | |
left[0] = 1; | |
right[n-1] = 1; | |
for (int i=1; i<n; i++) { | |
left[i] = left[i-1]*nums[i-1]; | |
right[n-i-1] = right[n-i]*nums[n-i]; | |
} | |
for (int i=0; i<n; i++) | |
arr[i] = left[i]*right[i]; | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment