문제
https://leetcode.com/problems/fizz-buzz/
Fizz Buzz - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
생각
우선 리스트를 증가하는 숫자로 채워놓고
Fizz와 Buzz들어갈 부분만 바꿔주면 될 듯?
나는 그냥 for문 돌려서 조건 맞으면 값 바꿔줘야겠다.
-
그냥 바로 for문 돌리면서 append해도 굿!
코드
class Solution:
def fizzBuzz(self, n: int) -> List[str]:
R = [str(i+1) for i in range(n)]
for i in range(n):
if (i+1) % 3 == 0 and (i+1) % 5 == 0:
R[i] = "FizzBuzz"
elif (i+1) % 3 == 0:
R[i] = "Fizz"
elif (i+1) % 5 == 0:
R[i] = "Buzz"
return R
'문제 > 릿코드' 카테고리의 다른 글
[릿코드/LeetCode] 169. Majority Element (파이썬3/Python3) (0) | 2021.07.18 |
---|---|
[릿코드/LeetCode] 206. Reverse Linked List (파이썬3/Python3) (0) | 2021.07.18 |
[릿코드/LeetCode] 342. Power of Four (파이썬3/Python3) (4) | 2021.07.11 |
[릿코드/LeetCode] 551. Student Attendance Record I (파이썬3/Python3) (0) | 2021.07.11 |
[릿코드/LeetCode] 14. Longest Common Prefix (파이썬3/Python3) (0) | 2021.07.10 |