100% Python solution


  • 0
    P
    u = [1]
    
    i = [0,0,0]
    
    def nthUglyNumber(self, n):
        if len(self.u)-1 < n:
            self.do(n)
        return self.u[n-1]
    
    def do(self,n):
        l = len(self.u)
        while l < n:
            u1,u2,u3 = 2*self.u[self.i[0]],3*self.u[self.i[1]],5*self.u[self.i[2]]
            m = min(u1,u2,u3)
            if m == u1:
                self.i[0] +=1
            if m == u2:
                self.i[1] +=1
            if m == u3:
                self.i[2] +=1
            self.u.append(m)
            l += 1
    

    '''


Log in to reply
 

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