File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ The `☢` means that you need to have a LeetCode Premium Subscription.
27
27
| --- | ------------------------------------------------------------ | ------------------ |
28
28
| 265 | [ Paint House II] | |
29
29
| 264 | [ Ugly Number II] | |
30
- | 263 | [ Ugly Number] | |
30
+ | 263 | [ Ugly Number] | [ C ] ( src/263.c ) |
31
31
| 261 | [ Graph Valid Tree] ☢ | |
32
32
| 260 | [ Single Number III] | |
33
33
| 259 | [ 3Sum Smaller] ☢ | |
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdbool.h>
3
+ #include <assert.h>
4
+
5
+ bool isUgly (int num ) {
6
+ if (num <= 0 ) return false;
7
+
8
+ while (num > 1 ) {
9
+ bool flag = false;
10
+
11
+ if (num % 2 == 0 ) {
12
+ flag = true;
13
+ num /= 2 ;
14
+ }
15
+ if (num % 3 == 0 ) {
16
+ flag = true;
17
+ num /= 3 ;
18
+ }
19
+ if (num % 5 == 0 ) {
20
+ flag = true;
21
+ num /= 5 ;
22
+ }
23
+
24
+ if (!flag ) return false;
25
+ }
26
+
27
+ return true;
28
+ }
29
+
30
+ int main () {
31
+ assert (isUgly (0 ) == false);
32
+ assert (isUgly (1 ) == true);
33
+ assert (isUgly (6 ) == true);
34
+ assert (isUgly (14 ) == false);
35
+
36
+ printf ("all test passed.\n" );
37
+ return 0 ;
38
+ }
You can’t perform that action at this time.
0 commit comments