[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;
    }