10000 Merge branch 'develop' of github.com:kylesliu/awesome-golang-leetcode… · folai/awesome-golang-leetcode@5daa7d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5daa7d8

Browse files
committed
Merge branch 'develop' of github.com:kylesliu/awesome-golang-leetcode into develop
2 parents 536a536 + 59f0c51 commit 5daa7d8

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

src/0507.Perfect-Number/README.md

Lines changed: 19 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# [507. Perfect Number][title]
2+
3+
## Description
4+
5+
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.
6+
7+
Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not.
8+
9+
**Example 1:**
10+
11+
```
12+
Input: 28
13+
Output: True
14+
Explanation: 28 = 1 + 2 + 4 + 7 + 14
15+
```
16+
17+
18+
19+
[title]: https://leetcode.com/problems/perfect-number/

src/0507.Perfect-Number/Solution.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package Solution
2+
3+
func checkPerfectNumber(num int) bool {
4+
if num == 0 {
5+
return false
6+
}
7+
sum := 0
8+
9+
for i := 1; i <= num/2; i++ {
10+
if num%i == 0 {
11+
sum += i
12+
13+
}
14+
15+
}
16+
return sum == num
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestCheckPerfectNumber(t *testing.T) {
9+
cases := []struct {
10+
name string
11+
input int
12+
expected bool
13+
}{
14+
{"Test case 1", 28, true},
15+
}
16+
17+
for _, testcase := range cases {
18+
t.Run(testcase.name, func(t *testing.T) {
19+
got := checkPerfectNumber(testcase.input)
20+
if !reflect.DeepEqual(got, testcase.expected) {
21+
t.Fatalf("expected: %v, but got: %v, with input: %v",
22+
testcase.expected, got, testcase.input)
23+
}
24+
})
25+
}
26+
}

src/0709.To-Lower-Case/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [709. To Lower Case][title]
2+
3+
## Description
4+
5+
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
6+
7+
**Example 1:**
8+
9+
```
10+
Input: "Hello"
11+
Output: "hello"
12+
```
13+
14+
15+
**Example 2:**
16+
17+
```
18+
Input: "LOVELY"
19+
Output: "lovely"
20+
```
21+
22+
**Example 3:**
23+
24+
```
25+
Input: "here"
26+
Output: "here"
27+
```
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
[title]: https://leetcode.com/problems/to-lower-case/
39+

src/0709.To-Lower-Case/Solution.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Solution
2+
3+
import "strings"
4+
5+
func toLowerCase(str string) string {
6+
return strings.ToLower(str)
7+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestSolution(t *testing.T) {
9+
cases := []struct {
10+
name string
11+
input string
12+
expect string
13+
}{
14+
{"Test case 1", "HELLO", "hello"},
15+
{"Test case 2", "here", "here"},
16+
{"Test case 1", "LOVELY", "lovely"},
17+
}
18+
19+
for _, testcase := range cases {
20+
t.Run(testcase.name, func(t *testing.T) {
21+
got := toLowerCase(testcase.input)
22+
if !reflect.DeepEqual(got, testcase.expect) {
23+
t.Fatalf("expected: %v, but got: %v, with input: %v ", testcase.expect, got, testcase.input)
24+
}
25+
})
26+
}
27+
}

0 commit comments

Comments
 (0)
0