public class Solution { /* * @param nums: Given an integers array A * @return: A long long array B and B[i]= A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1] */ public List<Long> productExcludeItself(List<Integer> nums) { List<Long> B = new ArrayList<>(); if(nums.size() == 1) { B.add((long) 1); return B; } for (int i = 0; i < nums.size(); i++) { long temp = 1; for (int j = 0; j < nums.size(); j++) { if(j == i) { continue; } temp *= nums.get(j); } B.add( temp); } return B; } }