File tree Expand file tree Collapse file tree 4 files changed +110
-3
lines changed Expand file tree Collapse file tree 4 files changed +110
-3
lines changed Original file line number Diff line number Diff line change @@ -44,18 +44,18 @@ func Test_twoSum(t *testing.T) {
44
44
{
45
45
name : "no target sum" ,
46
46
args : args {
47
- nums : []int {9 ,2 , 99 },
47
+ nums : []int {9 , 2 , 99 },
48
48
target : 1000 ,
49
49
},
50
50
want : nil ,
51
51
},
52
52
{
53
53
name : "3,2,4" ,
54
54
args : args {
55
- nums : []int {3 ,2 , 4 },
55
+ nums : []int {3 , 2 , 4 },
56
56
target : 6 ,
57
57
},
58
- want : []int {1 ,2 },
58
+ want : []int {1 , 2 },
59
59
},
60
60
}
61
61
Original file line number Diff line number Diff line change
1
+ package fizz
2
+
3
+ import "strconv"
4
+
5
+ func fizzBuzz (n int ) []string {
6
+ res := make ([]string , n )
7
+ for i := 1 ; i <= n ; i ++ {
8
+ if i % 15 == 0 {
9
+ res [i - 1 ] = "FizzBuzz"
10
+ continue
11
+ }
12
+
13
+ if i % 3 == 0 {
14
+ res [i - 1 ] = "Fizz"
15
+ continue
16
+ }
17
+
18
+ if i % 5 == 0 {
19
+ res [i - 1 ] = "Buzz"
20
+ continue
21
+ }
22
+
23
+ res [i - 1 ] = strconv .Itoa (i )
24
+ }
25
+
26
+ return res
27
+ }
Original file line number Diff line number Diff line change
1
+ package fizz
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func Test_fizzBuzz (t * testing.T ) {
10
+ type args struct {
11
+ n int
12
+ }
13
+ tests := []struct {
14
+ name string
15
+ args args
16
+ want []string
17
+ }{
18
+ {
19
+ name : "" ,
20
+ args : args {
21
+ n : 15 ,
22
+ },
23
+ want : []string {
24
+ "1" ,
25
+ "2" ,
26
+ "Fizz" ,
27
+ "4" ,
28
+ "Buzz" ,
29
+ "Fizz" ,
30
+ "7" ,
31
+ "8" ,
32
+ "Fizz" ,
33
+ "Buzz" ,
34
+ "11" ,
35
+ "Fizz" ,
36
+ "13" ,
37
+ "14" ,
38
+ "FizzBuzz" ,
39
+ },
40
+ },
41
+ }
42
+ for _ , tt := range tests {
43
+ t .Run (tt .name , func (t * testing.T ) {
44
+ got := fizzBuzz (tt .args .n )
45
+ assert .Equal (t , tt .want , got )
46
+ })
47
+ }
48
+ }
Original file line number Diff line number Diff line change
1
+ # 412. Fizz Buzz
2
+
3
+ < https://leetcode.com/problems/fizz-buzz/ >
4
+
5
+ Write a program that outputs the string representation of numbers from 1 to n.
6
+
7
+ But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
8
+
9
+ Example:
10
+
11
+ ``` text
12
+ n = 15,
13
+
14
+ Return:
15
+ [
16
+ "1",
17
+ "2",
18
+ "Fizz",
19
+ "4",
20
+ "Buzz",
21
+ "Fizz",
22
+ "7",
23
+ "8",
24
+ "Fizz",
25
+ "Buzz",
26
+ "11",
27
+ "Fizz",
28
+ "13",
29
+ "14",
30
+ "FizzBuzz"
31
+ ]
32
+ ```
You can’t perform that action at this time.
0 commit comments