Skip to content

Commit bb29741

Browse files
committed
0263
1 parent ee7a3bc commit bb29741

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rust/0263-ugly-number.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
impl Solution {
2+
pub fn is_ugly(n: i32) -> bool {
3+
if n < 1 {
4+
return false;
5+
}
6+
let mut n = n;
7+
let ugly_primes = vec![2, 3, 5];
8+
9+
for prime in ugly_primes {
10+
while n % prime == 0 {
11+
n /= prime;
12+
}
13+
}
14+
15+
n == 1
16+
}
17+
}

0 commit comments

Comments
 (0)