Fizz Buzz the result is 1 1 Fizz,and I cannot know where is wrong


  • -1
    L

    class Solution {
    public:
    vector<string> fizzBuzz(int n) {
    vector<string> a;
    if(n<0) return a;
    int m=1;
    string str;
    stringstream stream;
    for(;m<=n;++m)
    {
    if(m%3==0&&m%5==0) a.push_back("FizzBuzz");
    else if(m%3==0) a.push_back("Fizz");
    else if(m%5==0) a.push_back("Buzz");
    else{
    stream<<m;
    stream>>str;
    a.push_back(str);
    }
    }
    return a;
    }
    };


Log in to reply
 

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