classSolution:defisUgly(self,num:int) ->bool:if num <1:returnFalsedefis_ugly(number):if number ==1:returnTrue cond2, cond3, cond5 =False,False,Falseif number %2==0: cond2 =is_ugly(number //2)if number %3==0: cond3 =is_ugly(number //3)if number %5==0: cond5 =is_ugly(number //5)return cond2 or cond3 or cond5returnis_ugly(num)
classSolution:defisUgly(self,num:int) ->bool:if num <1:returnFalsewhile num >1:if num %2==0: num //=2elif num %3==0: num //=3elif num %5==0: num //=5else:returnFalsereturnTrue