bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 412. Fizz Buzz

412. Fizz Buzz

Leetcode Solutions

Approach: Naive Approach

  1. Initialize an empty list called answer.
  2. Loop over numbers from 1 to n (inclusive).
  3. For each number i, do the following: a. If i is divisible by both 3 and 5, append 'FizzBuzz' to answer. b. Else if i is divisible by 3, append 'Fizz' to answer. c. Else if i is divisible by 5, append 'Buzz' to answer. d. Else, append the string representation of i to answer.
  4. Return the answer list.
UML Thumbnail

Approach: String Concatenation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...