当前位置:网站首页>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;
}
}
边栏推荐
- Nebula importer data import practice
- One question per day (2022-07-02) - Minimum refueling times
- [发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
- Scala基础教程--18--集合(二)
- 奥迪AUDI EDI INVOIC发票报文详解
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- 2021 合肥市信息学竞赛小学组
- 更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
- A method of using tree LSTM reinforcement learning for connection sequence selection
- 学习路之PHP--phpstudy创建项目时“hosts文件不存在或被阻止打开”
猜你喜欢

正则替换【JS,正则表达式】

One question per day (2022-07-02) - Minimum refueling times

Microservice architecture debate between radical technologists vs Project conservatives

小发猫物联网平台搭建与应用模型
redis分布式锁的8大坑总结梳理

2022 ByteDance daily practice experience (Tiktok)

Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology

神经网络物联网平台搭建(物联网平台搭建实战教程)

奥迪AUDI EDI INVOIC发票报文详解

字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
随机推荐
完善的js事件委托
Go microservice (II) - detailed introduction to protobuf
资料下载 丨首届腾讯技术开放日课程精华!
基于C语言的菜鸟驿站管理系统
Microservice architecture debate between radical technologists vs Project conservatives
Use canal and rocketmq to listen to MySQL binlog logs
Scala basic tutorial -- 18 -- set (2)
6.26CF模拟赛E:价格最大化题解
Cache é JSON uses JSON adapters
C language printing exercise
Li Kou brush question diary /day3/2022.6.25
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
删除字符串中出现次数最少的字符【JS,Map排序,正则】
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
千万不要只学 Oracle、MySQL!
Scala基础教程--14--隐式转换
国元期货是正规平台吗?在国元期货开户安全吗?
Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
输入的查询SQL语句,是如何执行的?