263. Ugly Number(判断是否是丑数 剑指offer34)
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 boolean isUgly(int n) {
if(n==0) return false;
while(n%2==0) n/=2;
while(n%3==0) n/=3;
while(n%5==0) n/=5;
return n==1;
}
}
263. Ugly Number(判断是否是丑数 剑指offer34)的更多相关文章
- 【easy】263. Ugly Number 判断丑数
class Solution { public: bool isUgly(int num) { ) return false; ) return true; && num % == ) ...
- 264. Ugly Number II(丑数 剑指offer 34)
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 ...
- 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 ...
- 263 Ugly Number 丑数
编写程序判断给定的数是否为丑数.丑数就是只包含质因子 2, 3, 5 的正整数.例如, 6, 8 是丑数,而 14 不是,因为它包含了另外一个质因子 7.注意: 1 也可以被当做丑数. 输 ...
- [LeetCode] 263. Ugly Number 丑陋数
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- 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
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
随机推荐
- ytu 1052: 写一函数,将两个字符串连接(水题,指针练习)
1052: 写一函数,将两个字符串连接 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 343 Solved: 210[Submit][Status][ ...
- 打印系统所有的PID
#!/usr/bin/env python #-*- coding:utf-8 -*- ''' 打印系统所有的PID ''' import os def get_all_pid(): for pid ...
- log4j2设置日志文件读写权限(filePermissions)
spring-boot使用log4j2作为日志插件的时候需要设置日志文件的读写权限,可以File 上增加filePermissions,如: <File name="File" ...
- DLL入口函数
BOOL APIENTRY DllMain(HINSTANCE hInst /* Library instance handle. */, DWORD reason /* Rea ...
- string整理
/* scanf是c语言的,而string是c++的类,所以不能使用scanf直接读入 */ #include<cstdio> #include<string>//注意支持库 ...
- 【IIS】IIS 7.0/7.5 绑定
window 7 IIS 7.0/7.5 默认站点不存在,甚至Http的绑定类型也无法选择,而绑定类型是空的,或者是别的.此时IIS无法正常创建IIS站点,而创建IIS站点的页面也不是通常的页面,此时 ...
- 云服务器 ECS Linux 保存用户登录操作命令记录
转载自 : https://help.aliyun.com/knowledge_detail/41210.html 云服务器 ECS Linux 如果要保存用户登录操作记录,则可以通过在 /etc/p ...
- LeetCode 笔记系列11 First Missing Positive [为什么我们需要insight]
题目: Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2 ...
- dao---service---action分层结构
此文转载于http://blog.csdn.net/jay198746/article/details/4698709 之前有看过一些ssh2中采用dao---service---action分层结构 ...
- git 学习(3)文件删除恢复
git学习(3) 撤销编辑 如果我们在编辑版本a的时候,如果在没有add之前,发现需要重新编辑版本a怎么办呢,可以通过git reset --hard comm_id, commit_id是版本a的提 ...