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 ...
随机推荐
- 上海期货交易所CTP行情和交易接入
发布时间:2018-09-25 技术:C++11,动态库的制作 概述 CTP的接入Demo 详细 代码下载:http://www.demodashi.com/demo/14125.html 本 ...
- IDEA导入项目jar包红线, cannot resolve symbol xxxx问题
简单来说遇到的这种情况2种方式解决了, 不知道还有没有其他原因的. 1.reimport包 2.清缓存重启 针对1方法: a.确实不缺包: 可以先注释掉pom文件中的jar包, 此时idea会提示im ...
- java hashcode的Delphi实现
程序使用java做后台服务,数据处理时使用了java的hashcode,Delphi程序也需要生成这个hashcode,为了一致,所以要在Delphi下实现和Java一样的算法. 下面即Delphi版 ...
- mysql--SQL编程(关于mysql中的日期,实例,判断生日是否为闰年) 学习笔记2.1
关于日期处理的实例: 从mysql给出的 example 这个是官方源码下载以及导入,http://dev.mysql.com/doc/employee/en/employees-installati ...
- Mysql DBA 20天速成教程
Mysql DBA 20天速成教程 基本知识1.mysql的编译安装2.mysql 第3方存储引擎安装配置方法3.mysql 主流存储引擎(MyISAM/innodb/MEMORY)的特点4.字符串编 ...
- java 取模运算% 实则取余 简述 例子 应用在数据库分库分表
java 取模运算% 实则取余 简述 例子 应用在数据库分库分表 取模运算 求模运算与求余运算不同.“模”是“Mod”的音译,模运算多应用于程序编写中. Mod的含义为求余.模运算在数论和程序设计中 ...
- ubuntu远程桌面连接windows系统
现在用ubuntu系统,公司买了个windows的服务器,需要给配置一套环境,来回跑很麻烦,就想windows下可以的远程桌面,Linux应该也有. 现在自己的ubuntu13.10,无法进入桌面的“ ...
- Swift 类型检查与类型转换
前言 在 Swift 语言中一般使用 is 关键字实现类型检查,使用 as 关键字实现类型转换,除此之外还可以通过构造器和方法来实现类型转换. 1.类型检查 1.1 使用 is 检查 类型检查操作符 ...
- 【C语言】练习2-8
题目来源:<The C programming language>中的习题P38 练习2-1: 编写一个函数rightrot(x,n),该函数返回将x循环右移(即从最右端移除的位将从 ...
- EF GroupBy 根据key 分组 再把key求和(取决于每条数据中 arr的条数) arr 中有多少条数据 就把多少个key 加起来
List<A> alist = new List<A>{ ,b=,c=,d=,e=}, ,b=,c=,d=,e=}, ,b=,c=,d=,e=}, ,b=,c=,d=,e=}, ...