File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ ##==================================
2
+ ## Leetcode
3
+ ## Student: Vandit Jyotindra Gajjar
4
+ ## Year: 2020
5
+ ## Problem: 412
6
+ ## Problem Name: Fizz Buzz
7
+ ##===================================
8
+ #Write a program that outputs the string representation of numbers from 1 to n.
9
+ #
10
+ #But for multiples of three it should output “Fizz” instead of the number and
11
+ #for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
12
+ #
13
+ #Example:
14
+ #
15
+ #n = 15,
16
+ #
17
+ #Return:
18
+ #[
19
+ # "1",
20
+ # "2",
21
+ # "Fizz",
22
+ # "4",
23
+ # "Buzz",
24
+ # "Fizz",
25
+ # "7",
26
+ # "8",
27
+ # "Fizz",
28
+ # "Buzz",
29
+ # "11",
30
+ # "Fizz",
31
+ # "13",
32
+ # "14",
33
+ # "FizzBuzz"
34
+ #]
35
+ class Solution :
36
+ def fizzBuzz (self , n ):
37
+ tmp = [] #Initialize empty tmp list
38
+ for i in range (0 , n ): #Loop through numbers
39
+ if (i + 1 ) % 15 == 0 : #Condition-check: If number gives no remainder when divided by 15.
40
+ tmp .append ("FizzBuzz" ) #We append FizzBuzz
41
+ elif (i + 1 ) % 3 == 0 : #Condition-check: Elif number gives no remainder when divided by 3.
42
+ tmp .append ("Fizz" ) #We append Fizz
43
+ elif (i + 1 ) % 5 == 0 : #Condition-check: Elif number gives no remainder when divided by 5.
44
+ tmp .append ("Buzz" ) #We append Buzz
45
+ else : #Condition-check: Else
46
+ tmp .append (str (i + 1 )) #We append number in string format
47
+ return tmp #We return tmp at the end
You can’t perform that action at this time.
0 commit comments