Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5daa7d8

Browse files
committed
Merge branch 'develop' of github.com:kylesliu/awesome-golang-leetcode into develop
2 parents536a536 +59f0c51 commit5daa7d8

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
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+
funccheckPerfectNumber(numint)bool {
4+
ifnum==0 {
5+
returnfalse
6+
}
7+
sum:=0
8+
9+
fori:=1;i<=num/2;i++ {
10+
ifnum%i==0 {
11+
sum+=i
12+
13+
}
14+
15+
}
16+
returnsum==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+
funcTestCheckPerfectNumber(t*testing.T) {
9+
cases:= []struct {
10+
namestring
11+
inputint
12+
expectedbool
13+
}{
14+
{"Test case 1",28,true},
15+
}
16+
17+
for_,testcase:=rangecases {
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+
functoLowerCase(strstring)string {
6+
returnstrings.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+
funcTestSolution(t*testing.T) {
9+
cases:= []struct {
10+
namestring
11+
inputstring
12+
expectstring
13+
}{
14+
{"Test case 1","HELLO","hello"},
15+
{"Test case 2","here","here"},
16+
{"Test case 1","LOVELY","lovely"},
17+
}
18+
19+
for_,testcase:=rangecases {
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)

[8]ページ先頭

©2009-2025 Movatter.jp