博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Ugly Number
阅读量:6894 次
发布时间:2019-06-27

本文共 446 字,大约阅读时间需要 1 分钟。

No matter what language you use on the OJ, you may refer to for a solution. The C++ is rewritten below, just really concise.

1 class Solution {2 public:3     bool isUgly(int num) {4         for (int i = 2; i < 6 && num; i++)5             while (!(num % i)) num /= i;6         return num == 1;7     }8 };

Note that i = 4 will simply be skipped after we try to divide by 2 as much as possible.

 

转载于:https://www.cnblogs.com/jcliBlogger/p/4742618.html

你可能感兴趣的文章
python基础知识~ 函数详解
查看>>
简单几何(线段与直线的位置) POJ 3304 Segments
查看>>
DFS/BFS+思维 HDOJ 5325 Crazy Bobo
查看>>
P2312 解方程
查看>>
P2447 [SDOI2010]外星千足虫
查看>>
uva 796(求割边)
查看>>
铁大Facebook——十天冲刺(7)
查看>>
Oracle连接:TNS出错
查看>>
前端开发中,如何优化图像?图像格式的区别?
查看>>
借助第八代智能英特尔® 酷睿™ i7 处理器和 Unreal Swarm* 的强大性能快速构建光照...
查看>>
java之运算符
查看>>
洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers Label:ExWater
查看>>
[K/3Cloud]进度条控件编程接口
查看>>
hduoj1090A+B for Input-Output Practice (II)
查看>>
hduoj1096A+B for Input-Output Practice (VIII)
查看>>
Mac Mysql 修改初始化密码
查看>>
textarea 禁止拉伸
查看>>
Struts2运行流程
查看>>
Numpy学习2
查看>>
ios解决本地私有库出现的bug
查看>>