Skip to content

Commit

Permalink
leetcode: Add 0263
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed May 27, 2024
1 parent 52edfda commit 045df21
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/leetcode/0263.ugly-number/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "lc-0263-ugly-number"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
4 changes: 4 additions & 0 deletions src/leetcode/0263.ugly-number/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#

[问题描述](../problems/)
40 changes: 40 additions & 0 deletions src/leetcode/0263.ugly-number/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2024 Xu Shaohua <[email protected]>. All rights reserved.
// Use of this source is governed by General Public License that can be found
// in the LICENSE file.

pub fn is_ugly1(n: i32) -> bool {
let mut n = n;
while n != 0 && n % 2 == 0 {
n /= 2;
}
while n != 0 && n % 3 == 0 {
n /= 3;
}
while n != 0 && n % 5 == 0 {
n /= 5;
}
n == 1
}

pub type SolutionFn = fn(i32) -> bool;

fn check_solution(func: SolutionFn) {
assert!(func(6));
assert!(func(1));
assert!(!func(14));
assert!(!func(0));
}

fn main() {
check_solution(is_ugly1);
}

#[cfg(test)]
mod tests {
use super::{check_solution, is_ugly1};

#[test]
fn test_is_ugly1() {
check_solution(is_ugly1);
}
}

0 comments on commit 045df21

Please sign in to comment.