Clean Code with C++


  • 0
    Y
    class Solution {
    public:
        vector<string> fizzBuzz(int n) {
            vector<string> result{n, "hi"};
            for (int i=1; i<=n; i++){
                result[i-1] = (i%15==0) ? "FizzBuzz" : (i%5==0) ? "Buzz" : (i%3==0) ? "Fizz" : to_string(i);
            }
            return result;
        }
    };
    

  • 0
    Y
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.