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

书脊

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

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930