当前位置:网站首页>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;
}
}
边栏推荐
- Li Kou brush question diary /day4/6.26
- 基于lex和yacc的词法分析器+语法分析器
- 性能优化之关键渲染路径
- [2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
- 一种将Tree-LSTM的强化学习用于连接顺序选择的方法
- 数组中的第K个最大元素
- [go ~ 0 to 1] read, write and create files on the sixth day
- 信息学奥赛一本通 1336:【例3-1】找树根和孩子
- Build your own website (15)
- Cache é JSON uses JSON adapters
猜你喜欢
![[go ~ 0 to 1] read, write and create files on the sixth day](/img/cb/b6785ad7d7c7df786f718892a0c058.png)
[go ~ 0 to 1] read, write and create files on the sixth day

Lex and yacc based lexical analyzer + parser

Wireshark网络抓包

【uniapp】uniapp开发app在线预览pdf文件

中国农科院基因组所汪鸿儒课题组诚邀加入

奥迪AUDI EDI INVOIC发票报文详解

Scala basic tutorial -- 13 -- advanced function

激进技术派 vs 项目保守派的微服务架构之争

基于lex和yacc的词法分析器+语法分析器

使用canal配合rocketmq监听mysql的binlog日志
随机推荐
IBM WebSphere MQ retrieving messages
Don't just learn Oracle and MySQL!
千万不要只学 Oracle、MySQL!
[go ~ 0 to 1] read, write and create files on the sixth day
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
使用canal配合rocketmq监听mysql的binlog日志
大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
2022健康展,北京健博会,中国健康展,大健康展11月13日
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
Scala基础教程--17--集合
奥迪AUDI EDI INVOIC发票报文详解
Is the securities account opened by qiniu safe?
Li Kou brush question diary /day1/2022.6.23
[mathematical basis of machine learning] (I) linear algebra (Part 1 +)
Li Kou brush question diary /day2/2022.6.24
Rookie post station management system based on C language
Lex and yacc based lexical analyzer + parser
LeetCode FizzBuzz C#解答
From automation to digital twins, what can Tupo do?
SSL证书续费相关问题详解