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; } }
LintCode 50---数组剔除元素后的乘积
猜你喜欢
转载自www.cnblogs.com/cnmoti/p/10828361.html
今日推荐
周排行