4.20
也没啥可总结的。。。。。。
public class Solution {
/**
* @param A: Given an integers array A
* @return: A Long array B and B[i]= A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1]
*/
public ArrayList<Long> productExcludeItself(ArrayList<Integer> A) {
// write your code
int size = A.size();
if(size == 0 ){
return null;
}
ArrayList<Long> B = new ArrayList<Long>();
for(int i = 0; i < size;i++){
long res = 1;
for(int j = 0; j < size; j++){
if(j == i){
continue;
}
else{
if(res == 0){
break;
}
res = res * A.get(j);
}
}
B.add(res);
}
return B;
}
}