LeetCode之旅(17)-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 typically treated as an ugly number.
思路分析:
题目的意思是判断一个数字是否由2,3,5乘积组成,1是除外的,座位符合条件的。通过是否是整除的思路解决,另外一个问题的思考:判断一个数字是不是被2,3,5相加组成
代码:
public class Solution {
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;
}
}
LeetCode之旅(17)-Ugly Number的更多相关文章
- 【leetcode❤python】263. Ugly Number
class Solution(object): def isUgly(self, num): if num<=0:return False comlist=[2 ...
- 【leetcode】313. Super Ugly Number
题目如下: 解题思路:总结一下这么几点,一出一进,优先级队列排序,保证每次输出的都是当前的最小值.解法大致如图: 代码如下: #include<map> #include<queue ...
- [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 ...
- leetcode@ [263/264] Ugly Numbers & Ugly Number II
https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...
- 【一天一道LeetCode】#263. Ugly Number
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- <LeetCode OJ> 26 / 264 / 313 Ugly Number (I / II / III)
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- 力不从心 Leetcode(ugly number heap) 263, 264,313
Leetcode ugly number set (3 now) new ugly number is generated by multiplying a prime with previous g ...
随机推荐
- 插件占坑,四大组件动态注册前奏(三) 系统BroadCast的注册发送流程
转载请注明出处:http://blog.csdn.net/hejjunlin/article/details/52204143 前言:为什么要了解系统Activity,Service,BroadCas ...
- Python图片处理库之PIL
这个模块对于Python2.7 的windows64位电脑而言,还真的是不好找啊.这里分享一个下载链接吧,需要的朋友可以下载下来.PIL For Windows64 Python2.7下面分享一下这个 ...
- Java基础---Java---基础加强---类加载器、委托机制、AOP、 动态代理技术、让动态生成的类成为目标类的代理、实现Spring可配置的AOP框架
类加载器 Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个类负责加载特定位置的类:BootStrap,ExtClassLoader,AppClassLoader 类加载器也是Jav ...
- android之.9.png详解
.9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法,使图片支持在android 环境下的自适应展示. PNG,是一种非失真性压缩位图图形文件格 ...
- ajax核心技术1---XMLHttpRequset对象的使用
AJAX即"Asynchronous Javascript And XML"(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术.AJAX = 异步 Ja ...
- Android的ProgressBar进度条-android学习之旅(三十一)
ProgressBar 简介 ProgressBar是一种很常用的Ui,用于给复杂的操作显示进度,提供更好的用户相应.使用setProgress()incrementProgressBy()来设置进度 ...
- CentOS 64-bit下安装JDK和Tomcat并设置Tomcat开机启动操作步骤
准备文件如下: 1.CentOS-6.4-x86_64-bin-DVD1.iso 2.jdk-7u67-linux-x64.rpm 3.apache-tomcat-7.0.55.tar.gz 安装步骤 ...
- Linux中的查找命令find
原文:http://blog.csdn.net/windone0109/article/details/2817792 查找目录:find /(查找范围) -name '查找关键字' -type d ...
- React Native之hellWord
初始化项目工程 进入自己的工作空间然后shift+鼠标右键打开命令行窗口执行如下命令创建RN工程HelloWorld: 然后使用Android Studio打开AVD Manager创建模拟器,在打开 ...
- 多态 OC——第十天
1.多态 父类指针指向子类对象 没有继承就没有多态 联系前面知识才能清楚什么是多态,所以放到最后面总结小知识点,有前面的知识会对多态更好的了解,会觉得简单很多,但是看此篇博文需要 ...