Leet Code OJ 263. Ugly Number [Difficulty: Easy]
题目:
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。例如6,8是丑数,而14不是一个丑数,因为它有一个质因子7。
提示,1作为特例被认为是一个丑数。
分析:
尝试去除以2,3,5,如果可以除尽,则递归调用函数,如果都除不尽,说明这不是一个丑数。
代码:
public class Solution {public boolean isUgly(int num) {if(num<=0){return false;}if(num==1){return true;}if(num%2==0){return isUgly(num/2);}if(num%3==0){return isUgly(num/3);}if(num%5==0){return isUgly(num/5);}return false;}
}
Leet Code OJ 263. Ugly Number [Difficulty: Easy]相关推荐
- Leet Code OJ 202. Happy Number [Difficulty: Easy]
题目: Write an algorithm to determine if a number is "happy". A happy number is a number def ...
- Leet Code OJ 66. Plus One [Difficulty: Easy]
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...
- Leet Code OJ 112. Path Sum [Difficulty: Easy]
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...
- Leet Code OJ 283. Move Zeroes [Difficulty: Easy]
题目: Given an array nums, write a function to move all 0's to the end of it while maintaining the rel ...
- Leet Code OJ 292. Nim Game [Difficulty: Easy]
题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...
- Leet Code OJ 344. Reverse String [Difficulty: Easy]
题目: Write a function that takes a string as input and returns the string reversed. Example: Given s ...
- Leet Code OJ 28. Implement strStr() [Difficulty: Easy]
题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...
- Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]
题目: Given a string containing just the characters , determine if the input string is valid. The brac ...
最新文章
- IJCAI 2019:中国团队录取论文超三成,北大、南大榜上有名
- PyTorch机器学习自动化:自动框架搜索、超参优化
- Pytorch 词嵌入word_embedding2实例(加载已训练词向量)
- 学习程序开发的方法,仅供参考吧
- System Verilog Assertion for debug
- C程序设计语言现代方法05:选择语句
- 类字面常量和静态代码执行顺序
- linux/work
- WindStyle ExifInfo for Windows Live Writer发布
- bak 服务器备份文件怎么恢复,bak文件怎么还原
- linux基础ppt下载,《Linux基础》PPT课件.ppt
- 第19部分- Linux x86 64位汇编GDB单步调试
- docker 设备共享
- 计算机的防呆接口,PC接口全释:防呆口很重要,小心硬插烧硬件!
- mysql主从配置duxi_DUX主题
- crontab 定时任务时间格式设置
- vue3 腾讯地图输入地址或拖动标记获取经纬度
- 代码补全漫谈(1) - 从TabNine说起
- 涂鸦智能在香港双重主板上市:市值112亿港元 年营收3亿美元
- [转载] 全本张广泰——第十二回 广泰退贼寇 技惊哈大人