File tree Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 5555| [ Graph] ( https://github.com/fluency03/leetcode-java/blob/master/src/graph ) |
5656
5757
58- # Total: 531
58+ # Total: 532
5959
6060| Easy | Medium | Hard | - |
6161| :-------:| :-------:| :----:| :---:|
62- | 141 | 288 | 90 | 12 |
62+ | 142 | 288 | 90 | 12 |
6363
6464
6565| Question | Solution | Difficulty |
381381| [ 408. Valid Word Abbreviation] ( https://leetcode.com/problems/valid-word-abbreviation/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/ValidWordAbbreviation408.java ) | Easy |
382382| [ 409. Longest Palindrome] ( https://leetcode.com/problems/longest-palindrome/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/LongestPalindrome409.java ) | Easy |
383383| [ 410. Split Array Largest Sum] ( https://leetcode.com/problems/split-array-largest-sum/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/SplitArrayLargestSum410.java ) | Hard |
384+ | [ 412. Fizz Buzz] ( https://leetcode.com/problems/fizz-buzz/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/FizzBuzz412.java ) | Easy |
384385| [ 414. Third Maximum Number] ( https://leetcode.com/problems/third-maximum-number/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/ThirdMaximumNumber414.java ) | Easy |
385386| [ 415. Add Strings] ( https://leetcode.com/problems/add-strings/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/AddStrings415.java ) | Easy |
386387| [ 416. Partition Equal Subset Sum] ( https://leetcode.com/problems/partition-equal-subset-sum/ ) | [ Solution] ( https://github.com/fluency03/leetcode-java/blob/master/src/PartitionEqualSubsetSum416.java ) | Medium |
Original file line number Diff line number Diff line change 1+ /**
2+ * Write a program that outputs the string representation of numbers from 1 to n.
3+ *
4+ * But for multiples of three it should output “Fizz” instead of the number and
5+ * for the multiples of five output “Buzz”. For numbers which are multiples of
6+ * both three and five output “FizzBuzz”.
7+ *
8+ * Example: n = 15,
9+ * Return:
10+ * [
11+ * "1",
12+ * "2",
13+ * "Fizz",
14+ * "4",
15+ * "Buzz",
16+ * "Fizz",
17+ * "7",
18+ * "8",
19+ * "Fizz",
20+ * "Buzz",
21+ * "11",
22+ * "Fizz",
23+ * "13",
24+ * "14",
25+ * "FizzBuzz"
26+ * ]
27+ */
28+
29+ public class FizzBuzz412 {
30+ public List <String > fizzBuzz (int n ) {
31+ List <String > res = new ArrayList <>();
32+ for (int i =1 ; i <=n ; i ++) {
33+ boolean isFizz = i % 3 == 0 ;
34+ boolean isBuzz = i % 5 == 0 ;
35+ if (isFizz && isBuzz ) {
36+ res .add ("FizzBuzz" );
37+ } else if (isFizz ) {
38+ res .add ("Fizz" );
39+ } else if (isBuzz ) {
40+ res .add ("Buzz" );
41+ } else {
42+ res .add (Integer .toString (i ));
43+ }
44+ }
45+ return res ;
46+ }
47+
48+ }
You can’t perform that action at this time.
0 commit comments