C++, one pass, simple solution.
Use three index for 2, 3, 5 in to trace the last generated numbers based on 2, 3, 5 and generate next number based on the last generated numbers.\n\n    class S
Use three index for 2, 3, 5 in to trace the last generated numbers based on 2, 3, 5 and generate next number based on the last generated numbers.\n\n    class Solution {\n    public:\n        int nthUglyNumber(int n) {\n            if(n<1)\n                return 0;\n    \n            int id2=0, id3=0, id5=0, rst=1;\n            vector<int> buf;\n    \n            while(--n)\n            {\n                buf.push_back(rst);\n    \n                int v2 = 2*(buf[id2]), v3 = 3*(buf[id3]), v5 = 5*(buf[id5]);\n                rst = min(v2, min(v3, v5));\n                \n                id2 += (rst == v2), id3 += (rst == v3), id5 += (rst == v5);\n            }\n            return rst;\n        }\n    };
[]