Question1Anugly numberis a positive integer whose prime factors are limited to2,3, and5.Given an integern, returntrueifnis anugly number**.Algorithm1Easy implementation, check if the number can be divided by 2 or 3 or 5, otherwise it's not an ugly number.Code1classSolution{publicbooleanisUgly(intn) {if(n<=0)returnfalse;while(n%2==0) {n/=2;}while(n%3==0) {n/=3;}while(n%5==0) {n/=5;}returnn==1;}}Question2Anugly numberis a positive integer whose prime factors are limited to2,3, and5.Given an integern, returnthenthugly number.Algorithm2This question is to generate the ugly number. Start from num1,
...
继续阅读
(34)