Last active
April 1, 2024 12:15
-
-
Save vamsitallapudi/ebf24ef885125bd8415f674699433842 to your computer and use it in GitHub Desktop.
This file contains 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
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