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 ...
随机推荐
- oauth2.0了解
http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html
- java web用于保持状态的4种方法
方法一:网址重写 通过在url地址后面添加若干的token作为查询字符串来实现.token的值一般为 键=值 url?key1=value1&key2=value2&...&k ...
- MVC Model数据验证
概述 上节我们学习了Model的数据在界面之间的传递,但是很多时候,我们在数据传递的时候为了确保数据的有效性,不得不给Model的相关属性做基本的数据验证. 本节我们就学习如何使用 System.Co ...
- SQLiteDatabase浅谈
(一).简介: Android通过 SQLite 数据库引擎来实现结构化数据的存储.在一个数据库应用程序中,任何类都可以通过名字对已经创建的数据库进行访问,但是在应用程序之外就不可以. SQLite ...
- windows 快捷键
Windows 系统 f6 在同一个应用的不同窗口进行切换 ctrl-shift 拖动,创建文件快捷方式 shift 右键点击文件 可以出现复制路径的菜单 WIN键组合键 Windows Key + ...
- Java 内存区域划分
JVM的内存区域划分 学过C语言的朋友都知道C编译器在划分内存区域的时候经常将管理的区域划分为数据段和代码段,数据段包括堆.栈以及静态数据区.那么在Java语言当中,内存又是如何划分的 ...
- CentOS7配置日志(VirtualBox)
版本为CentOS-Minimal 1.VirtualBox下安装CentOS. 新建虚拟机 下载CentOS,放入盘片,启动虚拟机,按提示开始安装(建议内存1G,硬盘10G以上) 2. 设置网络 ...
- 远程出发jenkins jobs
wget -O - -q "http://jenkins_server/job/ttt/buildWithParameters?TEST1=Value" wget -O - -q ...
- loadrunner generators (controller in windows)
http://my.oschina.net/u/2391658/blog/735690 http://blog.csdn.net/xu1314/article/details/7455114 http ...
- LeetCode Factor Combinations
原题链接在这里:https://leetcode.com/problems/factor-combinations/ 题目: Numbers can be regarded as product of ...