码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Ugly Number

时间:2015-08-19 19:38:23      阅读:143      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!