当前位置:网站首页>Leetcode fizzbuzz C # answer
Leetcode fizzbuzz C # answer
2022-07-04 19:20:00 【charlsdm】
- Fizz Buzz
Give you an integer n , Find out from 1 To n Of each integer Fizz Buzz Express , And use string array answer( Subscript from 1 Start ) Return results , among :
answer[i] == “FizzBuzz” If i At the same time 3 and 5 Multiple .
answer[i] == “Fizz” If i yes 3 Multiple .
answer[i] == “Buzz” If i yes 5 Multiple .
answer[i] == i ( In string form ) If none of the above conditions are met .
Example 1:
Input :n = 3
Output :[“1”,“2”,“Fizz”]
Example 2:
Input :n = 5
Output :[“1”,“2”,“Fizz”,“4”,“Buzz”]
Example 3:
Input :n = 15
Output :[“1”,“2”,“Fizz”,“4”,“Buzz”,“Fizz”,“7”,“8”,“Fizz”,“Buzz”,“11”,“Fizz”,“13”,“14”,“FizzBuzz”]
Tips :
1 <= n <= 104
Pass times 132,841 Submit the number 187,101
What kind of recruitment do you encounter this problem ?
Attach my AC C# Code
public class Solution
{
public List<string> FizzBuzz(int n)
{
List<string> mylist = new List<string>();
for(int i=0;i<n;i++)
{
mylist.Add((i + 1).ToString());
}
for(int i=0;i<mylist.Count;i++)
{
int temp = int.Parse(mylist[i]);
if(temp%3==0&&temp%5==0)
{
mylist[i] = "FizzBuzz";
}
else if(temp%3==0)
{
mylist[i] = "Fizz";
}
else if(temp%5==0)
{
mylist[i] = "Buzz";
}
}
return mylist;
}
}
边栏推荐
- Caché JSON 使用JSON适配器
- 一种将Tree-LSTM的强化学习用于连接顺序选择的方法
- Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
- Li Chi's work and life summary in June 2022
- ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
- 读写关闭的channel是啥后果?
- Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
- C language printing exercise
- Rookie post station management system based on C language
- Microservice architecture debate between radical technologists vs Project conservatives
猜你喜欢

Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?

Scala basic tutorial -- 13 -- advanced function

Li Kou brush question diary /day2/2022.6.24

Scala基础教程--19--Actor

Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join

Scala基础教程--18--集合(二)

TorchDrug教程

Li Kou brush question diary /day1/2022.6.23

Scala basic tutorial -- 17 -- Collection

Angry bird design based on unity
随机推荐
ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
My colleagues quietly told me that flying Book notification can still play like this
A method of using tree LSTM reinforcement learning for connection sequence selection
Torchdrug tutorial
删除字符串中出现次数最少的字符【JS,Map排序,正则】
Mxnet implementation of googlenet (parallel connection network)
Angry bird design based on unity
千万不要只学 Oracle、MySQL!
其他InterSystems %Net工具
C language printing exercise
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
Wireshark抓包TLS协议栏显示版本不一致问题
Li Chi's work and life summary in June 2022
《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
Scala基础教程--15--递归
问下各位大佬有用过cdc直接mysql to clickhouse的么
[release] a tool for testing WebService and database connection - dbtest v1.0
基于lex和yacc的词法分析器+语法分析器
Scala basic tutorial -- 19 -- actor
正则替换【JS,正则表达式】