LeetCode_263. 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.
Example 1:
Input: 6
Output: true
Explanation: 6 = 2 × 3
Example 2:
Input: 8
Output: true
Explanation: 8 = 2 × 2 × 2
Example 3:
Input: 14
Output: false
Explanation:14is not ugly since it includes another prime factor7.
Note:
1is typically treated as an ugly number.- Input is within the 32-bit signed integer range: [−231, 231 − 1].
package leetcode.easy;
public class UglyNumber {
public boolean isUgly(int num) {
if (num <= 0) {
return false;
}
while (num % 2 == 0) {
num = num / 2;
}
while (num % 3 == 0) {
num = num / 3;
}
while (num % 5 == 0) {
num = num / 5;
}
return num == 1;
}
@org.junit.Test
public void test() {
System.out.println(isUgly(6));
System.out.println(isUgly(8));
System.out.println(isUgly(14));
System.out.println(isUgly(0));
}
}
LeetCode_263. Ugly Number的更多相关文章
- [LeetCode] Super Ugly Number 超级丑陋数
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...
- [LeetCode] Ugly Number II 丑陋数之二
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- [LeetCode] Ugly Number 丑陋数
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- 【13_263】Ugly Number
简单题 Ugly Number My Submissions Question Total Accepted: 32635 Total Submissions: 94009 Difficulty: E ...
- Leetcode 313. super ugly number
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...
- Leetcode 264. Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- LeetCode 263 Ugly Number
Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...
- [LeetCode] Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- [LeetCode] Ugly Number
Ugly Number Total Accepted: 20760 Total Submissions: 63208 Difficulty: Easy Write a program to check ...
随机推荐
- 织梦cms 后台查看会员性别为空
织梦cms会员注册选择性别为保密时,在后台会员中心查看性别为空的修改方法 第一步:找到dede/templets/member_view.htm,在引号中添加保密就ok 再次修改后的结果
- MySQL 是怎么保证数据一致性的(转载)
在<写数据库同时发mq消息事务一致性的一种解决方案>一文的方案中把分布式事务巧妙转成了数据库事务.我们都知道关系型数据库事务能保证数据一致性,那数据库到底是怎么设计事务这一特性的呢? 一. ...
- Linux 命令-egrep
egrep 可以看着是grep的扩展,参数-e支持正则匹配 满足其中任一条件 egrep -e "tiaojian1|tiaojian2" test.txt
- 自用 微信小程序跳小程序
"window": { "navigationBarTextStyle": "black", "navigationBarTitl ...
- C# 字符串String相关
是否可以继承String类 不能,因为从定义上看String类是sealed类[密封]故不可以继承.当对一个类应用 sealed 修饰符时,此修饰符会阻止其他类从该类继承.若硬要写,则编译不通过 字符 ...
- Bzoj 1926: [Sdoi2010]粟粟的书架(二分答案+乱搞+主席树)
1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Sec Memory Limit: 552 MB Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱 ...
- 力扣50题 Pow(x,n)
本题是力扣网第50题. 实现 pow(x, n) ,即计算 x 的 n 次幂函数. 采用递归和非递归思路python实现. class Solution: #递归思路 def myPow_recurs ...
- 学习速率过大 or 过小
- linux 常用性能优化
linux 常用性能优化 1. 优化内核相关参数 配置文件/etc/sysctl.conf 配置方法直接将参数添加进文件每条一行. sysctl -a可以查看默认配置 sysctl -p 执行并检测是 ...
- 和小哥哥一起刷洛谷(6) 图论之SPFA算法
关于\(spfa\) spfa伪代码: void spfa(s){ 最短路数组全部设为无限大; 队列 q; 起点s入队; s离s的距离设为零; while(队列非空){ 取出队首;弹出队首; for( ...