首页 > 其他 > 详细

[LeetCode] Ugly Number

时间:2015-08-19 19:37:54      阅读:460      评论:0      收藏:0      [点我收藏+]

No matter what language you use on the OJ, you may refer to Stefan‘s post 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.

 

[LeetCode] Ugly Number

原文:http://www.cnblogs.com/jcliBlogger/p/4742618.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!