leetcode-easy-math-412 Fizz Buzz
mycode 99.06%
class Solution(object):
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
ops = ['Fizz','Buzz','FizzBuzz']
res = []
for i in range(n):
k = i + 1
if k%3 == 0 and k%5 == 0:
res.append(ops[2])
elif k%3 == 0 :
res.append(ops[0])
elif k%5 == 0:
res.append(ops[1])
else:
res.append(str(k))
return res
leetcode-easy-math-412 Fizz Buzz的更多相关文章
- [LeetCode&Python] Problem 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 412. Fizz Buzz solution: class Solution { public: vector<string> fizzBuzz(int n) { vec ...
- Java实现 LeetCode 412 Fizz Buzz
412. Fizz Buzz 写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz" ...
- 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 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 方法一:遍历判断 方法二:字符串相加 方法三:字典 日期 [L ...
- [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
写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...
- LeetCode之412. Fizz Buzz
-------------------------------------------- 虽然是从最简单的开始刷起,但木有想到LeetCode上也有这么水的题目啊... AC代码: public cl ...
- LeetCode 412 Fizz Buzz 解题报告
题目要求 Write a program that outputs the string representation of numbers from 1 to n. But for multiple ...
随机推荐
- git 基础命令 学习总结
首先介绍一个git 里工作流的概念: 你的本地仓库由 git 维护的三棵“树”组成.第一个是你的 工作目录,它持有实际文件:第二个是 缓存区(Index),它像个缓存区域,临时保存你的改动:最后是 H ...
- pl_sql例题
0. 准备工作: set serveroutput on hellowrold 程序 begindbms_output.put_line('hello world');end;/ [语法格式]--de ...
- 第十篇.6、python并发编程之IO模型
一 IO模型介绍 为了更好地了解IO模型,我们需要事先回顾下:同步.异步.阻塞.非阻塞 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非 ...
- poj 2033 Alphacode (dp)
Alphacode Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13378 Accepted: 4026 Descri ...
- matplotlib:python数据处理三剑客之一
1.基本使用 import numpy as np import matplotlib.pyplot as plt import pandas as pd # 生成一系列x x = np.linspa ...
- MSSQL数据库备份还原常用SQL语句及注意
.备份数据库 backup database db_name to disk='d:\db_name.bak' with format --通过使用with format可以做到覆盖任何现有的备份和创 ...
- [HDU 3521] [最小割] Being a Hero
题意: 在一个有向图中,有n个点,m条边$n \le 1000 \And \And m \le 100000$ 每条边有一个破坏的花费,有些点可以被选择并获得对应的金币. 假设一个可以选的点是$x$ ...
- Detecting Unstable Periodic Orbits in Chaotic Experimental Data (解析)
原文链接:https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.76.4705 发表在:PRL 1996 ---------------- ...
- Linux系统服务器 GNU Bash 环境变量远程命令执行漏洞修复命令
具体方法就是在ssh上执行 yum update bash 完成后重启VPS.
- Android 热修复(一)
名词: dex:java文件编译class 然后生成 dex文件在Android上运行: 1.dex分包: 2.找出出现问题的dex文件进行替换操作 3.下载dex文件,静默替换有问题的dex文件,进 ...