LeetCode----263. Ugly Number(Java)
- package isUgly263;
- /*
- * 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 typically treated as an ugly number.
- */
- public class Solution {
- public static boolean isUgly(int num) {
- if (num<=0)
- return false;
- while(num>5){
- if(num%2==0)
- num=num/2;
- else if(num%3==0)
- num=num/3;
- else if(num%5==0)
- num=num/5;
- else
- return false;
- }
- return true;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int num=14;
- System.out.println(isUgly(num));
- }
- }
LeetCode----263. Ugly Number(Java)的更多相关文章
- leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes
263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...
- LN : leetcode 263 Ugly Number
lc 263 Ugly Number lc 263 Ugly Number Write a program to check whether a given number is an ugly num ...
- Java [Leetcode 263]Ugly Number
题目描述: Write a program to check whether a given number is an ugly number. Ugly numbers are positive n ...
- [LeetCode] 263. Ugly Number 丑陋数
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- LeetCode 263 Ugly Number
Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...
- Leetcode 263 Ugly Number 数论 类似质因数分解
Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...
- (easy)LeetCode 263.Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- [leetcode] 263. Ugly Number (easy)
只要存在一种因数分解后,其因子是2,3,5中的一种或多种,就算是ugly数字. 思路: 以2/3/5作为除数除后,最后结果等于1的就是ugly数字 Runtime: 4 ms, faster than ...
- [LeetCode] 264. Ugly Number II 丑陋数 II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- 263. Ugly Number(C++)
263. Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are ...
随机推荐
- ArcGIS AddIN开发之COM对象写入注册表
做一个交互式绘制文字的工具,希望这次设置的Symbol,下次打开ArcMap时自动调用这个Symbol,并支持对其进行修改. 解决方法是将这个Symbol写入注册表中,每次自动读取上一次设置的Symb ...
- UIBezierPath 的使用
使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线 ...
- Hibernate saveOrUpdate方法到底是怎么执行的?
saveOrUpdate方法,如果传入的对象有主键就执行更新,没有就执行新增.这句话误导了很多人. 究竟是执行新增还是更新,是要有上下文环境的.这个环境就是主键策略的选择. 主键生成方式为 手动设置: ...
- ubuntu安装Python环境以及科学计算环境
参考:http://blog.csdn.net/a1311543690/article/details/ 1.sudo apt-get install python-pip pip是Python的一个 ...
- 浅谈scrum站立会议
什么是每日站立会议? 站立会议是让团队成员每日面对面站立互相交流他们所承担任务的进度.它的一个附带好处是让领导或经理能了解到工作情况.但本质上是为了团队交流,不是报告会议! 为什么开展每日 ...
- geometric median
The geometric median of a discrete set of sample points in a Euclidean space is the point minimizing ...
- iOS 3D touch 使用技巧
第一个 在桌面中3d Touch 打开菜单 由于本人纯属代码党,本次实现方法也只使用代码实现 到达到这个效果并不难,只需要在appdelegate中实现以下代码即可 ,当然也有缺点,就是这个app没运 ...
- PHPExcel导出数据
require_once './class/Excel/PHPExcel.php'; //将(1,1)转换成"A1"形式 function getCoordinate($row, ...
- Android RecyclerView的基本使用
Android RecyclerView 在去年的Google I/O大会上就推出来了,以前经常使用的ListView 继承的是AbsListView,而RecyclerView则直接继承 ViewG ...
- View的drawRect方法
1)此方法在View第一次在展示时调用,此后都用他的一个shotCut,可用setNeedsDisplay方法强制调用. 1)此方法在ViewDidAppear方法中才会调用.因此要想获得在drawR ...