Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Last active April 1, 2024 12:15
Show Gist options
  • Save vamsitallapudi/ebf24ef885125bd8415f674699433842 to your computer and use it in GitHub Desktop.
Save vamsitallapudi/ebf24ef885125bd8415f674699433842 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];
for(int i = 0; i< n; i++) {
int prod = 1;
for(int j = 0; j<n; j++) {
if(i==j) continue; // skipping in case if the indices are same
prod *=nums[j];
}
ans[i] = prod;
}
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment