C# accepted solution


  • 1
    K
    public IList<string> FizzBuzz(int n) {
        List<String> res = new List<String>();
        
        for (int i = 1; i != n+1; i++) {
            string fiz = "";
            if (i % 3 == 0) fiz = "Fizz"; 
            
            if (i % 5 == 0) fiz += "Buzz";
            
            if (fiz == "") fiz = "" + i;
            
            res.Add(fiz);
        }
        return res;
    }

Log in to reply
 

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