File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+ import java .util .*;
3
+
4
+ public class FizzBuzz {
5
+
6
+ public List <String > fizzBuzz (int n ) {
7
+ List <String > result = new ArrayList ();
8
+ for (int i = 1 ; i <= n ; i ++){
9
+ if (i %3 == 0 && i %5 == 0 ){
10
+ result .add ("FizzBuzz" );
11
+ } else if (i %3 == 0 ){
12
+ result .add ("Fizz" );
13
+ } else if (i %5 == 0 ){
14
+ result .add ("Buzz" );
15
+ } else {
16
+ result .add (Integer .toString (i ));
17
+ }
18
+ }
19
+ return result ;
20
+ }
21
+
22
+ }
Original file line number Diff line number Diff line change 2
2
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
3
3
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
4
4
| 415| [ Add Strings] ( https://leetcode.com/problems/add-strings/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/AddStrings.java ) | O(n)| O(1) | Easy|
5
+ | 412| [ Fizz Buzz] ( https://leetcode.com/problems/fizz-buzz/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/FizzBuzz.java ) | O(n)| O(1) | Easy|
5
6
|398|[ Random Pick Index] ( https://leetcode.com/problems/random-pick-index/ ) |[ Solution] ( ../../blob/master/MEDIUM/src/medium/RandomPickIndex.java ) | | | Medium| Reservoir Sampling
6
7
|397|[ Integer Replacement] ( https://leetcode.com/problems/integer-replacement/ ) |[ Solution] ( ../../blob/master/EASY/src/easy/IntegerReplacement.java ) | ? | ? | Easy| BFS
7
8
| 396| [ Rotate Function] ( https://leetcode.com/problems/rotate-function/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/RotateFunction.java ) | O(n^2) could be optimized to O(n) | O(1) | Easy|
You can’t perform that action at this time.
0 commit comments