Product of array itself worst case time complexity
class Solution {
public int[] productExceptSelf(int[] nums) {
int answer[]=new int[nums.length];
for(int i=0;i<nums.length;i++){
int product=1;
for(int j=0;j<nums.length;j++){
if(i!=j){
product=product*nums[j];
}
}
answer[i]=product;
}
return answer;
}
}
Comments
Post a Comment