当前位置:网站首页>LeetCode FizzBuzz C#解答
LeetCode FizzBuzz C#解答
2022-07-04 17:39:00 【charlsdm】
- Fizz Buzz
给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果,其中:
answer[i] == “FizzBuzz” 如果 i 同时是 3 和 5 的倍数。
answer[i] == “Fizz” 如果 i 是 3 的倍数。
answer[i] == “Buzz” 如果 i 是 5 的倍数。
answer[i] == i (以字符串形式)如果上述条件全不满足。
示例 1:
输入:n = 3
输出:[“1”,“2”,“Fizz”]
示例 2:
输入:n = 5
输出:[“1”,“2”,“Fizz”,“4”,“Buzz”]
示例 3:
输入:n = 15
输出:[“1”,“2”,“Fizz”,“4”,“Buzz”,“Fizz”,“7”,“8”,“Fizz”,“Buzz”,“11”,“Fizz”,“13”,“14”,“FizzBuzz”]
提示:
1 <= n <= 104
通过次数132,841提交次数187,101
请问您在哪类招聘中遇到此题?
附上我的AC C#代码
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;
}
}
边栏推荐
- Scala basic tutorial -- 13 -- advanced function
- 英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
- Scala基础教程--20--Akka
- 资料下载 丨首届腾讯技术开放日课程精华!
- Nebula importer data import practice
- ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
- Scala基础教程--13--函数进阶
- C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
猜你喜欢
神经网络物联网是什么意思通俗的解释
Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
Scala基础教程--20--Akka
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
读写关闭的channel是啥后果?
Scala基础教程--17--集合
TorchDrug教程
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
力扣刷題日記/day6/6.28
随机推荐
Li Kou brush question diary /day5/2022.6.27
From automation to digital twins, what can Tupo do?
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
Scala基础教程--13--函数进阶
Process of manually encrypt the mass-producing firmware and programming ESP devices
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
其他InterSystems %Net工具
Li Kou brush question diary /day7/6.30
Li Kou brush question diary /day3/2022.6.25
Deleting nodes in binary search tree
How is the entered query SQL statement executed?
自由小兵儿
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Scala basic tutorial -- 14 -- implicit conversion
输入的查询SQL语句,是如何执行的?
千万不要只学 Oracle、MySQL!
An example of multi module collaboration based on NCF
[uniapp] uniapp development app online Preview PDF file
What if the self incrementing ID of online MySQL is exhausted?
MXNet对GoogLeNet的实现(并行连结网络)