File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 164
164
383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
165
165
387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
166
166
405|[ Convert a Number to Hexadecimal] ( ./0405-convert-a-number-to-hexadecimal.js ) |Easy|
167
+ 412|[ Fizz Buzz] ( ./0412-fizz-buzz.js ) |Easy|
167
168
414|[ Third Maximum Number] ( ./0414-third-maximum-number.js ) |Easy|
168
169
419|[ Battleships in a Board] ( ./0419-battleships-in-a-board.js ) |Medium|
169
170
442|[ Find All Duplicates in an Array] ( ./0442-find-all-duplicates-in-an-array.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 412. Fizz Buzz
3
+ * https://leetcode.com/problems/fizz-buzz/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an integer n, return a string array answer (1-indexed) where:
7
+ * - answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
8
+ * - answer[i] == "Fizz" if i is divisible by 3.
9
+ * - answer[i] == "Buzz" if i is divisible by 5.
10
+ * - answer[i] == i (as a string) if none of the above conditions are true.
11
+ */
12
+
13
+ /**
14
+ * @param {number } n
15
+ * @return {string[] }
16
+ */
17
+ var fizzBuzz = function ( n ) {
18
+ return Array . from ( new Array ( n ) , ( _ , i ) => i + 1 ) . map ( i =>
19
+ i % 3 === 0 && i % 5 === 0
20
+ ? 'FizzBuzz' : i % 3 === 0 ? 'Fizz' : i % 5 === 0 ? 'Buzz' : String ( i )
21
+ ) ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments