TreeSet,Java Solution


  • 0
    D
    public int nthUglyNumber(int n) {
    	TreeSet<Long> set = new TreeSet<Long>();
    	set.add(new Long(1));
        for(int i=1;i<n;i++){
        	Long k = set.pollFirst();
        	set.add(k*2);
        	set.add(k*3);
        	set.add(k*5);
        }
        return set.first().intValue();
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.