当前位置:网站首页>LeetCode#412. Fizz Buzz
LeetCode#412. Fizz Buzz
2022-07-06 15:21:00 【Rufeng ZHHH】
subject ( Power button ):
Give you an integer n , Find out from 1 To n Of each integer Fizz Buzz Express , And use string array answer( Subscript from 1 Start ) Return results , among :
answer[i] == "FizzBuzz" If i At the same time 3 and 5 Multiple .
answer[i] == "Fizz" If i yes 3 Multiple .
answer[i] == "Buzz" If i yes 5 Multiple .
answer[i] == i ( In string form ) If none of the above conditions are met .
Example 1:
Input :n = 3
Output :["1","2","Fizz"]
Example 2:
Input :n = 5
Output :["1","2","Fizz","4","Buzz"]
This question is not difficult , It can be written in two ways .
Method 1 :
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
ls=[]
for i in range(1,n+1):
if i%3==0 and i%5==0:
ls.append("FizzBuzz")
elif i%3==0:
ls.append("Fizz")
elif i%5==0:
ls.append("Buzz")
else:
ls.append(str(i))
return lsMethod 2 :
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
answer=[0]*n
for i in range(1,n+1):
if i%3==0 and i%5==0:
answer[i-1]="FizzBuzz"
elif i%3==0:
answer[i-1]="Fizz"
elif i%5==0:
answer[i-1]="Buzz"
else:
answer[i-1]=str(i)
return answer边栏推荐
- What is "test paper test" in software testing requirements analysis
- Global and Chinese market for antiviral coatings 2022-2028: Research Report on technology, participants, trends, market size and share
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- 自动化测试你必须要弄懂的问题,精品总结
- ucore lab7 同步互斥 实验报告
- How to become a good software tester? A secret that most people don't know
- CSAPP homework answers chapter 789
- Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
- 基于485总线的评分系统
- Description of Vos storage space, bandwidth occupation and PPS requirements
猜你喜欢

Heap, stack, queue

How to build a nail robot that can automatically reply

Description of Vos storage space, bandwidth occupation and PPS requirements
遇到程序员不修改bug时怎么办?我教你

China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Do you know the performance testing terms to be asked in the software testing interview?

CSAPP shell lab experiment report

Eigen User Guide (Introduction)

Winter vacation daily question - maximum number of balloons

C4D quick start tutorial - creating models
随机推荐
Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
CSAPP shell lab experiment report
The minimum number of operations to convert strings in leetcode simple problem
51 lines of code, self-made TX to MySQL software!
想跳槽?面试软件测试需要掌握的7个技能你知道吗
HackTheBox-Emdee five for life
Iterators and generators
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL development - advanced query - take a good look at how it suits you
Heap, stack, queue
How to become a good software tester? A secret that most people don't know
Video scrolling subtitle addition, easy to make with this technique
ArrayList集合
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
Mysql database (II) DML data operation statements and basic DQL statements
Differences between select, poll and epoll in i/o multiplexing
Mysql database (V) views, stored procedures and triggers
软件测试Bug报告怎么写?
The most detailed postman interface test tutorial in the whole network. An article meets your needs
STC-B学习板蜂鸣器播放音乐2.0