Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created April 1, 2024 12:34
Show Gist options
  • Save vamsitallapudi/61b20d7583fa132e0ff791b8f2548ddf to your computer and use it in GitHub Desktop.
Save vamsitallapudi/61b20d7583fa132e0ff791b8f2548ddf to your computer and use it in GitHub Desktop.
class Solution {
public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] ans = new int[n];
int prod = 1;
for(int i = 0; i< n;i++) {
prod*=nums[i]; // product of all numbers in an array
}
for(int i = 0; i< n; i++) {
ans[i] = prod/nums[i];
}
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment