1
Fork 0
leetcode/source/fizz_buzz/mod.rs

17 lines
385 B
Rust
Raw Permalink Normal View History

2022-04-13 17:49:19 +00:00
pub fn fizz_buzz(number: i32) -> Vec<String> {
let mut result = vec![];
for index in 1..=number {
let string = match (index % 3 == 0, index % 5 == 0) {
(true, true) => "FizzBuzz".to_string(),
(true, false) => "Fizz".to_string(),
(false, true) => "Buzz".to_string(),
(false, false) => index.to_string(),
};
result.push(string);
}
result
}