当前位置:网站首页>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;
}
}
边栏推荐
- 【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- Download the first Tencent technology open day course essence!
- 技术分享 | 接口测试价值与体系
- sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
- 力扣刷题日记/day3/2022.6.25
- C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
- 基于unity的愤怒的小鸟设计
- Other InterSystems%net tools
- Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
猜你喜欢
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
力扣刷题日记/day5/2022.6.27
小发猫物联网平台搭建与应用模型
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
1、 Introduction to C language
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
Scala basic tutorial -- 19 -- actor
Halcon template matching
Microservice architecture debate between radical technologists vs Project conservatives
Wireshark抓包TLS协议栏显示版本不一致问题
随机推荐
Other InterSystems%net tools
发送和接收IBM WebSphere MQ消息
性能优化之关键渲染路径
2022年字节跳动日常实习面经(抖音)
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
Pb extended DLL development (super chapter) (VII)
redis分布式锁的8大坑总结梳理
Build your own website (15)
From automation to digital twins, what can Tupo do?
李迟2022年6月工作生活总结
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import 'fmt' func
Li Kou brush question diary /day8/7.1
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
一、C语言入门基础
How to download files using WGet and curl
Interpretation of SIGMOD '22 hiengine paper
php伪原创api对接方法
Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join
6.26cf simulation match B: solution to array reduction problem
Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)