Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 587 Bytes

412.fizz-buzz.md

File metadata and controls

27 lines (23 loc) · 587 Bytes

問題

https://leetcode.com/problems/fizz-buzz/

回答

初回の回答: 単純に modular

impl Solution {
    pub fn fizz_buzz(n: i32) -> Vec<String> {
        (1..=n)
            .map(|n| {
                if n % 15 == 0 {
                    "FizzBuzz".to_string()
                } else if n % 5 == 0 {
                    "Buzz".to_string()
                } else if n % 3 == 0 {
                    "Fizz".to_string()
                } else {
                    n.to_string()
                }
            })
            .collect::<Vec<String>>()
    }
}