当前位置:网站首页>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;
}
}
边栏推荐
- 发送和接收IBM WebSphere MQ消息
- 神经网络物联网应用技术学什么
- How to open an account is safe,
- Scala basic tutorial -- 12 -- Reading and writing data
- 力扣刷题日记/day2/2022.6.24
- 6.26cf simulation race e: solution to the problem of price maximization
- One question per day (2022-07-02) - Minimum refueling times
- Angry bird design based on unity
- Li Kou brush question diary /day7/2022.6.29
- 物联网应用技术的就业前景和现状
猜你喜欢

Go microservice (II) - detailed introduction to protobuf
![[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

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

神经网络物联网应用技术学什么

How is the entered query SQL statement executed?
![[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation](/img/63/8d5f875b4409511628faf2914836d3.png)
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation

力扣刷题日记/day1/2022.6.23

Build your own website (15)

奥迪AUDI EDI INVOIC发票报文详解

Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
随机推荐
删除字符串中出现次数最少的字符【JS,Map排序,正则】
Scala basic tutorial -- 19 -- actor
模板_判断素数_开方 / 六素数法
Scala基础教程--15--递归
中国农科院基因组所汪鸿儒课题组诚邀加入
Technology sharing | interface testing value and system
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
整理混乱的头文件,我用include what you use
PB的扩展DLL开发(超级篇)(七)
小发猫物联网平台搭建与应用模型
Process of manually encrypt the mass-producing firmware and programming ESP devices
基于lex和yacc的词法分析器+语法分析器
Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)
Digital "new" operation and maintenance of energy industry
Principle and application of ThreadLocal
Go microservice (II) - detailed introduction to protobuf
Scala basic tutorial -- 15 -- recursion
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
What if the self incrementing ID of online MySQL is exhausted?
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0