263. Ugly Number

一定要注意…………审题!!!!

 1     public boolean isUgly(int num) {
 2         if(num <= 0) {
 3             return false;
 4         }
 5         if(num == 1) {
 6             return true;
 7         }
 8         while(num % 2 == 0) {
 9             num /= 2;
10         }
11         while(num % 3 == 0) {
12             num /= 3;
13         }
14         while(num % 5 == 0) {
15             num /= 5;
16         }
17         System.out.println(num);
18         return (num == 1 || num == -1)? true: false;
19     }
时间: 2024-10-18 00:36:37

263. Ugly Number的相关文章

Leetcode 263. Ugly Number

263. Ugly Number Total Accepted: 65061 Total Submissions:173755 Difficulty: Easy Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly

263. Ugly Number(C++)

263. Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.

263. Ugly Number &amp;&amp; 264. Ugly Number II &amp;&amp; 313. Super Ugly Number

263. Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.

Leetcode 263. Ugly Number JAVA语言

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty

【LeetCode】263. Ugly Number

Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note

leetcode:263 Ugly Number-每日编程第十七题

Ugly Number Total Accepted: 31482 Total Submissions: 90982 Difficulty: Easy Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly whil

Java [Leetcode 263]Ugly Number

题目描述: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1

(easy)LeetCode 263.Ugly Number

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty

LeetCode之263. Ugly Number

------------------------------------------------------------- 如果一个数的质因子只包括2,3,5,那么这个数n可以表示为:n=2x+3y+5z AC代码: import java.math.BigInteger; public class Solution { public boolean isUgly(int n) { if(n<1) return false; while(n%2==0) n/=2; while(n%3==0) n