Menu Sidebar
Menu

two pass

[LintCode] Product of Array Exclude Itself

public ArrayList<Long> productExcludeItself(ArrayList<Integer> A) { ArrayList<Long> res = new ArrayList<Long>(); if(A.size()==0 || A == null) return res; long p = 1; for(int i = 0 ; i < A.size(); i++) { res.add(p); p *= A.get(i); } p = A.get(A.size()-1); for(int i = A.size()-2; i >= 0; i–) { res.set(i,p*res.get(i)); p *= A.get(i); } return res; […]

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930