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 | 31 |
Tags
- 우분투
- dacon
- PYTHON
- Git
- 백준
- 맥북
- 금융문자분석경진대회
- gs25
- hackerrank
- ChatGPT
- programmers
- 캐치카페
- 편스토랑
- 파이썬
- Docker
- 데이콘
- AI 경진대회
- Kaggle
- 코로나19
- Baekjoon
- 편스토랑 우승상품
- 프로그래머스
- github
- Real or Not? NLP with Disaster Tweets
- 자연어처리
- 프로그래머스 파이썬
- 더현대서울 맛집
- SW Expert Academy
- ubuntu
- leetcode
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