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
- 캐치카페
- 우분투
- 더현대서울 맛집
- hackerrank
- 코로나19
- 자연어처리
- 백준
- leetcode
- Docker
- Baekjoon
- SW Expert Academy
- github
- 파이썬
- dacon
- gs25
- AI 경진대회
- 편스토랑 우승상품
- 프로그래머스
- 금융문자분석경진대회
- 편스토랑
- PYTHON
- ubuntu
- 데이콘
- Kaggle
- programmers
- Git
- 맥북
- ChatGPT
- Real or Not? NLP with Disaster Tweets
- 프로그래머스 파이썬
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
SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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