-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path412-FizzBuzz.cs
34 lines (32 loc) · 988 Bytes
/
412-FizzBuzz.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Problem: https://leetcode.com/problems/fizz-buzz/
using System.Collections.Generic;
namespace LeetCode {
public partial class Solution {
public IList<string> FizzBuzz(int n) {
int index = 1;
var resultList = new List<string>();
while(index <= n) {
if (index % 3 == 0 && index % 5 == 0) {
resultList.Add("FizzBuzz");
index++;
continue;
}
else if(index % 3 == 0) {
resultList.Add("Fizz");
index++;
continue;
}
else if(index % 5 == 0) {
resultList.Add("Buzz");
index++;
continue;
}
else {
resultList.Add($"{index}");
index++;
}
}
return resultList;
}
}
}