Leetcode学习(10)—— Fizz Buzz
来源:互联网 发布:web项目绑定域名 编辑:程序博客网 时间:2024/05/16 08:16
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"]
# -*- coding:utf-8 -*-class Solution(object): def fizzBuzz(self, n): new_list = [] for i in range(1, n+1): if i % 15 == 0: new_list.append('FizzBuzz') elif i % 5 == 0: new_list.append('Buzz') elif i % 3 == 0: new_list.append('Fizz') else: new_list.append(str(i)) return new_list
0 0
- Leetcode学习(10)—— Fizz Buzz
- LeetCode —— 412. Fizz Buzz
- LeetCode每日一题——412. Fizz Buzz
- 【python】【leetcode】【算法题目412—Fizz Buzz】
- LeetCode 412. Fizz Buzz 题解(C++)
- LeetCode 412 Fizz Buzz(字符串模拟)
- LeetCode 412. Fizz Buzz
- LeetCode 412 Fizz Buzz
- [LeetCode]--412. Fizz Buzz
- LeetCode-412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- LeetCode #412: Fizz Buzz
- LeetCode 刷题: Fizz Buzz
- 【leetcode】412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- leetcode 412. Fizz Buzz
- Fizz Buzz ----LeetCode
- leetcode 412. Fizz Buzz
- 面试题50:求二叉树中两个节点的最近公共祖先
- nodejs api 设计
- Linux网络协议栈 — Frame Reception — NAPI vs 非NAPI
- 哪位大神可以发些无线液位变送器的相关应用实例方案
- ssh环境搭建——spring与hibernate整合
- Leetcode学习(10)—— Fizz Buzz
- 唐山市韩城镇2017年实拍图(韩城规划、新兴工业、唐通路、航天国轩)
- shell编程2(makefile)
- python-pandas
- 贵州房卡麻将 房卡贵阳三丁拐 遵义麻将 安顺麻将商业源码
- 纯css实现气泡对话框尖角处理
- Eclipse项目中系统文件介绍
- android 多媒体数据库二
- linux 设备驱动模型