1. Fizz Buzz Easy

526

785

Favorite

Share 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”.

Example:

n = 15,

Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz" ]

思路:遍历range(1,n+1),分支处理

代码:python3

class Solution:def fizzBuzz(self, n: int):arr=[]for i in range(1,n+1):if i%3==0 and i%5==0:arr.append("FizzBuzz")elif i%3==0:arr.append("Fizz")elif i%5==0:arr.append("Buzz")else:arr.append(str(i))return arr
复制代码

转载于:https://juejin.im/post/5d030170e51d4510835e028a

lc412. Fizz Buzz相关推荐

  1. LeetCode简单题之Fizz Buzz

    题目 给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果,其中: answer[i] == "FizzBu ...

  2. LeetCode 1195. Fizz Buzz Multithreaded--并发系列题目--Java 解法--AtomicInteger/CountDownLatch/CyclicBarrier

    题目地址:Fizz Buzz Multithreaded - LeetCode Write a program that outputs the string representation of nu ...

  3. leetcode 412. Fizz Buzz

    Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...

  4. [重构到模式-Chain of Responsibility Pattern]把Fizz Buzz招式重构到责任链模式

    写一段程序从1打印到100,但是遇到3的倍数时打印Fizz,遇到5的倍数时打印Buzz,遇到即是3的倍数同时也是5的倍数时打印FizzBuzz.例如: 1 2 Fizz 4 Buzz Fizz 7 8 ...

  5. 【快乐水题】412. Fizz Buzz

    原题: 力扣链接:412. Fizz Buzz 题目简述: 给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果,其中 ...

  6. Lintcode9 Fizz Buzz solution 题解

    [题目描述] Given number n. Print number from 1 to n. But: when number is divided by 3, print "fizz& ...

  7. LeetCode之Fizz Buzz

    1.题目 Write a program that outputs the string representation of numbers from 1 to n. But for multiple ...

  8. 【Python CheckiO 题解】Fizz Buzz

    CheckiO 是面向初学者和高级程序员的编码游戏,使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务,从而提高你的编码技能,本博客主要记录自己用 Python 在闯关时的做题思 ...

  9. leetcode412. Fizz Buzz

    写一个程序,输出从 1 到 n 数字的字符串表示. 1. 如果 n 是3的倍数,输出"Fizz": 2. 如果 n 是5的倍数,输出"Buzz": 3.如果 n ...

最新文章

  1. 2022-2028年中国环卫行业产业链深度调研及投资前景预测报告
  2. Web 开发人员必备的随机 JSON 数据生成工具
  3. Spring-AOP 基于Schema配置切面
  4. Grunt 新手一日入门
  5. oracle物理DG管理-redo数据传输,应用与三种模式
  6. 跟我学Java(配光盘)(跟我学)
  7. HDU2546_用01背包做
  8. kafka java.net.UnknownHostException: node4 Error connecting to node node4:9092
  9. 再想想-----***
  10. weka分类器怎么设置类别_AI 迁移学习怎么玩?手把手教你实战迁移学习
  11. selenium定位方式
  12. 方阵的迹(trace)及其微分(导数)
  13. 梯度提升决策树GBDT
  14. Eureka注册服务列表显示ip+端口
  15. SQL注入时order by 后面加数字的作用
  16. 点击按钮下载Excel表格
  17. 深度学习-根据日志画loss-acc折线图
  18. FTP主动模式和被动模式!
  19. java怎么换行_java换行符如何使用
  20. 阿里工业互联网平台白皮书 – 数据驱动的新价值网络 - 0910.zip阿里工业互联网平台白皮书 – 数据驱动的新价值网络 -

热门文章

  1. linux脚本重定向到输入,linux shell输入输出重定向
  2. 从乘法表JAVA意思4_四、Java从头开始-我的九九乘法表(二)
  3. Kernel i2c gpio spi pinctrl platform 分析讲解 (未完待续)
  4. linux i2c 设备 操作说明
  5. 网页编程html link,Web--CSS控制页面(link与import方式区别)详解
  6. python查题_python 数据库连表查询习题
  7. micropython比c_选择C/C++还是选择MicroPython来开发?(第0章-第三节)
  8. C# 将数据写入PDF文档
  9. zabbix3 通过snmpv3监控linux主机
  10. 记一次关于MySQL与PHP的蠢事