Using three queues, Java solution
public int nthUglyNumber(int n) {\n        Queue<Long> q2 = new LinkedList<Long>();\n        Queue<Long> q3 = new LinkedList<Long>();\n        Queue<Long> q5 = 
    public int nthUglyNumber(int n) {\n        Queue<Long> q2 = new LinkedList<Long>();\n        Queue<Long> q3 = new LinkedList<Long>();\n        Queue<Long> q5 = new LinkedList<Long>();\n        Long res = 1L;\n        q2.add(2L);q3.add(3L);q5.add(5L);\n        while(n-- > 1){\n            if(q2.peek() < q3.peek() && q2.peek() < q5.peek()){\n                res = q2.poll();\n                q2.add(res*2);q3.add(res*3);q5.add(res*5);\n            }else if(q3.peek() < q2.peek() && q3.peek() < q5.peek()){\n                res = q3.poll();\n                q3.add(res*3);q5.add(res*5);\n            }else {\n                res = q5.poll();\n                q5.add(res*5);\n            }\n        }\n        return res.intValue();\n    }
[]