488ms C++


  • 0
    B
    class Solution {
    public:
        int nthUglyNumber(int n)
        {
            set<long long int> ugly;
            ugly.insert(1);
            long long int minUgly=0;
            for(int i=1;i<=n;i++)
            {
                minUgly=*ugly.lower_bound(minUgly+1);
                ugly.insert(minUgly*2);
                ugly.insert(minUgly*3);
                ugly.insert(minUgly*5);
            }
            return minUgly;
        }
    };
    

Log in to reply
 

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