Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Ugly Number - C
Views: 2 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdbool.h>
// @leet start
bool isUgly(int n) {
    while (true) {
        if (n < 1) {
            return false;
        }
        if (n % 5 == 0) {
            n /= 5;
            continue;
        }
        if (n % 3 == 0) {
            n /= 3;
            continue;
        }
        if (n % 2 == 0) {
            n /= 2;
            continue;
        }
        break;
    }
    return n == 1;
}
// @leet end