当前位置:网站首页>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;
}
}
边栏推荐
- 基于lex和yacc的词法分析器+语法分析器
- 2022 ByteDance daily practice experience (Tiktok)
- Nebula Importer 数据导入实践
- Go微服务(二)——Protobuf详细入门
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- 基于C语言的菜鸟驿站管理系统
- Li Chi's work and life summary in June 2022
- Send and receive IBM WebSphere MQ messages
- 【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
- 大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
猜你喜欢
物联网应用技术的就业前景和现状
What types of Thawte wildcard SSL certificates provide
LeetCode第300场周赛(20220703)
My colleagues quietly told me that flying Book notification can still play like this
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
redis分布式锁的8大坑总结梳理
Scala basic tutorial -- 20 -- akka
Halcon template matching
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
A method of using tree LSTM reinforcement learning for connection sequence selection
随机推荐
Perfect JS event delegation
2022年字节跳动日常实习面经(抖音)
redis分布式锁的8大坑总结梳理
Principle and application of ThreadLocal
使用FTP
[uniapp] uniapp development app online Preview PDF file
What types of Thawte wildcard SSL certificates provide
使用SSH
整理混乱的头文件,我用include what you use
从实时应用角度谈通信总线仲裁机制和网络流控
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
node_exporter部署
中国农科院基因组所汪鸿儒课题组诚邀加入
基于lex和yacc的词法分析器+语法分析器
激进技术派 vs 项目保守派的微服务架构之争
IBM WebSphere MQ retrieving messages
李迟2022年6月工作生活总结
repeat_P1002 [NOIP2002 普及组] 过河卒_dp
Download the first Tencent technology open day course essence!
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转