题目要求:

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

my answer:

测试错误分析

1 range(n)的使用,记住range(2)代表0,1 是从0开始的,所以上述遍历之后的 i 要变为 i+1

2 s%3==0 , 对于小于3的数也是成立的,所以这里分开讨论了

3 首先if 同时整除3和5的数,否则会出错

4 如果 output.append(“u”),直接加双引号会出错,输出"u" ,而不输出遍历的数字,所以需要用函数 str( )

leetcode--笔记8 Fizz Buzz的更多相关文章

  1. LeetCode算法题-Fizz Buzz(Java实现)

    这是悦乐书的第221次更新,第233篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第88题(顺位题号是412). 编写一个程序,输出从1到n的数字的字符串表示.但对于三的 ...

  2. 【LeetCode】412. Fizz Buzz 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...

  3. 【leetcode】412. Fizz Buzz

    problem 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...

  4. 力扣(LeetCode)412. Fizz Buzz

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

  5. LeetCode之412. Fizz Buzz

    -------------------------------------------- 虽然是从最简单的开始刷起,但木有想到LeetCode上也有这么水的题目啊... AC代码: public cl ...

  6. [LeetCode] Fizz Buzz 嘶嘶嗡嗡

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

  7. LeetCode Fizz Buzz

    原题链接在这里:https://leetcode.com/problems/fizz-buzz/ 题目: Write a program that outputs the string represe ...

  8. LeetCode——Fizz Buzz

    LeetCode--Fizz Buzz Question Write a program that outputs the string representation of numbers from ...

  9. [LeetCode] 412. Fizz Buzz 嘶嘶嗡嗡

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

  10. LeetCode 412. Fizz Buzz

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

随机推荐

  1. 【转】 url中文乱码问题

    [转自]http://blog.csdn.net/rascalboy520/article/details/2511175 在URL中传递参数,是通过HTTP报头来传递的.并不是类似于通过表单来传递, ...

  2. 两个List中的补集

    /** * 获取两个List的不同元素 * @param list1 * @param list2 * @return */ private static List getDiffrent(List ...

  3. 【[SCOI2008]奖励关】

    又抄了一篇题解 要凉了要凉了,开学了我还什么都不会 文化课凉凉,NOIP还要面临爆零退役的历史进程 这道题挺神的,期望+状态压缩 我们设\(dp[i][S]\)表示在第\(i\)天前,捡的宝物状态为\ ...

  4. idea中使用git进行clone、分支切换、pull、push等

    转:https://blog.csdn.net/xiaobai__lee/article/details/81081128 https://blog.csdn.net/geng31/article/d ...

  5. 7、springmvc的自动配置

    1.springmvc的自动配置 文档:https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#boot ...

  6. SqlMapConfig.xml配置文件

    SqlMapConfig.xml中配置的内容和顺序如下: 1.1 properties(属性) mybatis的属性加载顺序.读取顺序:properties------>resource或url ...

  7. HDU 2048 神、上帝以及老天爷(错排概率问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2048 神.上帝以及老天爷 Time Limit: 2000/1000 MS (Java/Others) ...

  8. 绘图驱动-OSD原理2

    转载自:http://blog.pfan.cn/programming/21209.html 现在已经可以通过修改存储单元内容来改变OSD的像素,但还有个关键的问题是如何根据需要来进行操作,即如何将某 ...

  9. Hadoop 学习之——HDFS

    HDFS是HADOOP中的核心技术之一——分布式文件存储系统.Hadoop的作者Doug Cutting 和Mike 是根据Google发布关于GFS 的研究报告所设计出的分布式文件存储系统. 一.H ...

  10. 使用OpenVPN连通管理多个阿里云VPC网络

    这篇文章比较长,将从需求.思路.原理.架构.实施步骤.细节分析.高可用等几个方面来讲述OpenVPN的使用,如果看到很熟悉的内容或者不感兴趣的部分,请您跳过. 需求 公司网络环境更换,导致原来连接阿里 ...