Skip to content

Commit 2dce58a

Browse files
committed
264
1 parent 422ce3e commit 2dce58a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Aug-18-24.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def nthUglyNumber(self, n: int) -> int:
3+
ug = [1]
4+
x,y,z = 0,0,0
5+
while len(ug)<n:
6+
least = min(ug[x]*2,ug[y]*3,ug[z]*5)
7+
if least not in ug:
8+
ug.append(least)
9+
if least == ug[x]*2:
10+
x+=1
11+
elif least == ug[y]*3:
12+
y+=1
13+
elif least == ug[z]*5:
14+
z+=1
15+
return ug[-1]

0 commit comments

Comments
 (0)