题目要求:

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. SP34096 【DIVCNTK - Counting Divisors (general)】

    题目 求 \[\sum_{i=1}^n \sigma(i^k)\] 我们先来设一个函数\(f(i)=\sigma(i^k)\) 根据约数个数定理 \[f(p)=\sigma(p^k)=k+1\] \[ ...

  2. Linux.开关机&登出&用户管理

    关机重启: shutdown:         shutdown –h now 立该进行关机         shudown -h 1 "hello, 1 分钟后会关机了"    ...

  3. ajax 三级联动商品分类(转载)

    转载  自  jines     http://www.cnblogs.com/lijinblogs/p/5759399.html 思路分析:效果:当页面加载时,利用ajax异步向后台请求数据,加载一 ...

  4. Selenium应用代码(常见封装的方法二)

    滚动窗口: //将滚动条滚到适合的位置 , 方法一 public static void setScroll(WebDriver driver,int height){ try { // String ...

  5. stixel上边缘

    上图是2^x-1的曲线,取值范围在(-1,正无穷) 上面两个公式组成了隶属函数(membership)表示隶属度,隶属度就是衡量这个点同下边缘点是否属于同一个物体.实际上M函数就是2^x-1,但M函数 ...

  6. 父窗口和iframe子窗口之间相互传递参数和调用函数或方法

    1.父窗口向子窗口传递参数: 可以在url中添加参数:2.html?a=1&b=2&c=3 然后在子页面上可用js解析,提供一个函数: function getQueryStr(sAr ...

  7. Office365学习笔记—获取当前用户

    1,页面上有个_spPageContextInfo对象,可以获取一些我们需要的东西. (1)获取当前用户Id var userId=_spPageContextInfo.userId; (2)获取当前 ...

  8. oracle cascade用法

    原文地址:https://www.cnblogs.com/moyijian/p/9940323.html#4111551 级联删除,比如你删除某个表的时候后面加这个关键字,会在删除这个表的同时删除和该 ...

  9. Cannot set HTTP gem source: “source https://rubygems.org not present in cache”

    My ruby version in Windows 10: > ruby -v ruby 2.3.1p112 (2016-04-26 revision 54768) [i386-mingw32 ...

  10. android软件开发之TextView控件常用属性

    TextView控件 text属性,设置显示的文本 textColor:设置文本颜色 textSize:设置文本字体大小 autoLink:设置文本为电话,URL连接等的时候是否显示为可点击的链接 c ...