Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- gs25
- hackerrank
- Docker
- ChatGPT
- 맥북
- github
- PYTHON
- ubuntu
- dacon
- programmers
- 프로그래머스
- 더현대서울 맛집
- 파이썬
- Baekjoon
- 프로그래머스 파이썬
- 백준
- 편스토랑 우승상품
- AI 경진대회
- SW Expert Academy
- 편스토랑
- Git
- leetcode
- 금융문자분석경진대회
- Real or Not? NLP with Disaster Tweets
- 캐치카페
- 우분투
- 코로나19
- 자연어처리
- Kaggle
- 데이콘
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 412. Fizz Buzz (Python) 본문
728x90
반응형
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"
]
Solution
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
answer = []
for i in range(1, n+1):
if i % 3 == 0 and i % 5 == 0:
answer.append("FizzBuzz")
elif i % 5 == 0:
answer.append("Buzz")
elif i % 3 == 0:
answer.append("Fizz")
else:
answer.append(str(i))
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 88. Merge Sorted Array (Python) (0) | 2020.06.14 |
---|---|
[leetCode] 136. Single Number (Python) (0) | 2020.06.13 |
[leetCode] 891. Sum of Subsequence Widths (Python) (0) | 2020.06.11 |
[HackerRank] HackerRank in a String! (Python) (0) | 2020.06.10 |
[leetCode] 268. Missing Number (Python) (0) | 2020.06.09 |
Comments