LeetCode 412 Fizz Buzz 解题报告
题目要求
Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
题目分析及思路
给定一正整数n,要求输出1-n的所有数字的的字符表示。其中三的倍数的数字输出“Fizz”,五的倍数的数字输出“Buzz”,若同时是三和五的倍数则输出“FizzBuzz”。可以遍历这个范围的所有数字,依次判断每个数字,对应输出它的字符表示。
python代码
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
ans = []
for i in range(1, n+1):
if i % 3 == 0 and i % 5 == 0:
ans.append('FizzBuzz')
elif i % 3 == 0:
ans.append('Fizz')
elif i % 5 == 0:
ans.append('Buzz')
else:
ans.append(str(i))
return ans
LeetCode 412 Fizz Buzz 解题报告的更多相关文章
- 【LeetCode】412. Fizz Buzz 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...
- Java实现 LeetCode 412 Fizz Buzz
412. Fizz Buzz 写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz" ...
- [LeetCode] 412. Fizz Buzz 嘶嘶嗡嗡
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
- LeetCode 412. Fizz Buzz
Problem: Write a program that outputs the string representation of numbers from 1 to n. But for mult ...
- LeetCode: 412 Fizz Buzz(easy)
题目: Write a program that outputs the string representation of numbers from 1 to n. But for multiples ...
- LeetCode - 412. Fizz Buzz - ( C++ ) - 解题报告 - to_string
1.题目大意 Write a program that outputs the string representation of numbers from 1 to n. But for multip ...
- 【leetcode】412. Fizz Buzz
problem 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
随机推荐
- 自己实现字符串转整数(不使用JDK的字符串转整数的方法)
[需求]: (1)如果输入的字符串为null,为空,或者不是数字,抛出异常: (2)如果输入的数字超出int的最大值或最小值,抛出异常: (3)输入的数字允许以+或-号开头,但如果输入的字符串只有&q ...
- 【GMT43液晶显示模块】发布原理图、出厂代码
GMT43是一款内置4.3寸真彩液晶显示模块,其内置高速ARM Cortex-M4处 理器,主频高达180MHz,并包含丰富的外设接口. GMT43拥有丰富的资源,包含RS-232,RS-485,RS ...
- 嵌入式开发之hi3519---i2c MDIO PHY uboot phy调试总结
首先调试检查硬件,再调试软件 首先仔细阅读phy和主芯片datesheet ,尤其着重阅读mii寄存器,它是mac和phy交换信息的媒介. 硬件注意:关于phy的芯片需要注意的有几点:1.mdio接口 ...
- [Object Tracking] Contour Detection through Tensorflow running on smartphone
From: 手机端运行卷积神经网络的一次实践 -- 基于 TensorFlow 和 OpenCV 实现文档检测功能 貌似不错的东西:移动端视觉识别模型:MobileNets Holistically- ...
- 自定义元素 v1:可重用网络组件
google文档 https://developers.google.cn/web/fundamentals/web-components/customelements 兼容性 https://can ...
- 网络推送通知:及时,相关和准确 (navigator.serviceWorker.register(), window.PushManager, new Notification)
google网络推送通知 https://developers.google.cn/web/fundamentals/push-notifications/ 服务工作线程:简介server worle ...
- Linux系统中的文件权限
r(read) 4 可读 w(write) 2 可写 x() 1 可执行 644 755 rw-r-r ...
- centos7 安装redis服务及phpredis扩展
闲话少说 服务器版本:centos7.6 64位 软件包:https://pan.baidu.com/s/1Gb4iz5mqLqNVWvvZdBiOMQ 提取码: xrhx 一.安装redis 放在/ ...
- 整合Solr与tomcat以及第一个core的配置
整合Solr与tomcat以及第一个core的配置 一.准备安装文件 Tomcat : apache-tomcat-8.5.32.tar.gz Solr:solr-5.3.1.tgz 二.创建目录并解 ...
- 一、在windows环境下修改pip镜像源的方法(以python3为例)
在windows环境下修改pip镜像源的方法(以python3为例) 1.在windows文件管理器中,输入 %APPDATA% 2.会定位到一个新的目录下,在该目录下新建pip文件夹,然后到pip文 ...