LeetCode263——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.
实现:
class Solution {
public:
bool isUgly(int num) {
if (num == 0) return false;
if (num == 1) return true;
if (num % 2 == 0) return isUgly(num/2);
else if (num % 3 == 0) return isUgly(num/3);
else if (num % 5 == 0) return isUgly(num/5);
return false;
}
};
LeetCode263——Ugly Number的更多相关文章
- LeetCode----263. Ugly Number(Java)
package isUgly263; /* * Write a program to check whether a given number is an ugly number. Ugly numb ...
- LeetCode263:Ugly Number
public bool IsUgly(int num) { if(num<1) return false; while(num>1) { if(num%2==0) { num=num/2; ...
- [Swift]LeetCode263. 丑数 | Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- [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 ...
随机推荐
- django之创建第1个项目并查看网页效果
1.c盘下创建djangoweb文件夹 Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation.保留所有权利. 2.C:\ ...
- CentOS7 通过代理上网
1.修改/etc/profile,增加以下内容: http_proxy=http://[代理地址]:[代理地址的端口]/ https_proxy=http://[代理地址]:[代理地址的端口]/ ex ...
- Androidstudio安装问题
非常多人在用Android Studio的时候会出现"'tools.jar' seems to be not in Android Studio classpath.Please ensur ...
- java动态代理技术
主要用来做方法的增强.让你能够在不改动源代码的情况下,增强一些方法,在方法运行前后做不论什么你想做的事情(甚至根本不去运行这种方法).由于在InvocationHandler的invoke方法中,你能 ...
- 关于js中的回调函数callback
来源于:http://www.jianshu.com/p/6bc353e5f7a3 前言 其实我一直很困惑关于js 中的callback,困惑的原因是,学习中这块看的资料少,但是平时又经常见,偶尔复制 ...
- iOS linker command failed with exit code 1 (use -v to see invocation)多种解决方案汇总
有时可能会遇到这种错误,关键是这种错误,有时只有这一句话,也不会给更多错误信息. 网上找了一些,总结了如下:(PS:以下是按照解决简易程度排序,不代表出现概率) 1.bitcode问题 解决如下:原因 ...
- grib文件
一.grib文件简介 WMO是世界气象组织,world meteorology organization. GRIB是WMO开发的一种用于交换和存储规则分布数据的二进制文件格式.最初GRIB表示&qu ...
- iOS应用间相互跳转
使用第三方用户登录,跳转到需授权的App.如QQ登录,微信登录等. 需要用户授权,还需要"返回到调用的程序,同时返回授权的用户名.密码". 应用程序推广,跳转到另一个应用程序(本机 ...
- 十五分钟介绍 Redis数据结构
下面是一个对Redis官方文档<A fifteen minute introduction to Redis data types>一文的翻译,如其题目所言,此文目的在于让一个初学者能通过 ...
- Tomcat 6 部署工程总结,使用JNDI数据源配置
工程需要用JNDI数据源方式部署到tomcat,参考网上文章后,经过配置测试,摸索出来了. 环境说明: 数据库:Oracle9i Web服务器:tomcat-6.0.33 tomcat启动方式 ...