Time limit out Python


  • 0
    W
    class Solution(object):
        def nthUglyNumber(self, n):
            """
            :type n: int
            :rtype: int
            """
            ug=[False,True]
            ct,i=1,2
            while ct<n: 
                if (i%2==0 and ug[i/2]==True) or (i%3==0 and ug[i/3]==True) or (i%5==0 and ug[i/5]==True):
                    ug.append(True)
                    ct+=1
                else:
                    ug.append(False)
                i+=1
            return i-1

Log in to reply
 

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