C# Solution


  • 0
    R
    public class Solution {
        public IList<string> FizzBuzz(int n) {
                IList<int> list = new List<int>();
                IList<string> list1 = new List<string>();
                string f = "Fizz";
                string b = "Buzz";
                string fb = f + b;
                for (int i = 1; i <= n; i++)
                {
                    list.Add(i);
                }
                foreach(int i in list)
                {
                    System.Console.WriteLine("i: " + i);
                    if ((i % 3 == 0) & (i % 5 == 0))
                    {
                        list1.Add(fb);
                    }
                    else if (i % 5 == 0)
                    {
                        list1.Add(b);
                    }
                    else if (i % 3 == 0)
                    {
                        list1.Add(f);
                    }
                    else
                    {
                        list1.Add(i.ToString());
                    }
                }
                return list1;
        }
    }
    

Log in to reply
 

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