Java solution -- using PriorityQueue
public int nthUglyNumber(int n) {\n        if(n==1) return 1;\n        PriorityQueue<Long> q = new PriorityQueue();\n        q.add(1l);\n        \n        for(l
    public int nthUglyNumber(int n) {\n        if(n==1) return 1;\n        PriorityQueue<Long> q = new PriorityQueue();\n        q.add(1l);\n        \n        for(long i=1; i<n; i++) {\n            long tmp = q.poll();\n            while(!q.isEmpty() && q.peek()==tmp) tmp = q.poll();\n            \n            q.add(tmp*2);\n            q.add(tmp*3);\n            q.add(tmp*5);\n        }\n        return q.poll().intValue();\n    }
[]