Java faster than 98%
Using a pre-product list to solve this problem\n\n\nclass ProductOfNumbers {\n    ArrayList<Integer> pList;\n    \n    public ProductOfNumbers() {\n        pLis
Using a pre-product list to solve this problem\n\n```\nclass ProductOfNumbers {\n    ArrayList<Integer> pList;\n    \n    public ProductOfNumbers() {\n        pList = new ArrayList<Integer>();\n    }\n    \n    public void add(int num) {\n        if (num == 0) pList.clear();\n        else \n            pList.add(pList.size() == 0 ? num : pList.get(pList.size() - 1)*num);\n    }\n    \n    public int getProduct(int k) {\n        if (k > pList.size()) return 0;\n        if (k == pList.size()) return pList.get(pList.size()-1);\n        return pList.get(pList.size()-1)/pList.get(pList.size()-1-k);\n    }\n}\n```
[]