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; […]

书脊

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

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031