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

Commit0f4041b

Browse files
committed
add 551 problem solution
1 parent26078bc commit0f4041b

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#[551. Student Attendance Record I][title]
2+
3+
##Description
4+
5+
ou are given a string representing an attendance record for a student. The record only contains the following three characters:
6+
'A' : Absent.
7+
'L' : Late.
8+
'P' : Present.
9+
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
10+
11+
You need to return whether the student could be rewarded according to his attendance record.
12+
**Example 1:**
13+
14+
```
15+
Input: "PPALLP"
16+
Output: True
17+
```
18+
19+
**Example 2:**
20+
21+
```
22+
Input: "PPALLL"
23+
Output: False
24+
```
25+
26+
**Tags:** Math, String
27+
28+
##题意
29+
>求2数之和
30+
31+
##题解
32+
33+
###思路1
34+
>。。。。
35+
36+
```go
37+
38+
```
39+
40+
###思路2
41+
>思路2
42+
```go
43+
44+
```
45+
46+
##结语
47+
48+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode][me]
49+
50+
[title]:https://leetcode.com/problems/student-attendance-record-i
51+
[me]:https://github.com/kylesliu/awesome-golang-leetcode
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Solution
2+
3+
funccheckRecord(sstring)bool {
4+
a,l:=0,0
5+
6+
fori,_:=ranges {
7+
ifs[i]=='A' {
8+
a++
9+
}
10+
ifs[i]=='L' {
11+
l++
12+
}else {
13+
l=0
14+
}
15+
16+
ifa>1||l>2 {
17+
returnfalse
18+
}
19+
20+
}
21+
22+
returntrue
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"strconv"
6+
"testing"
7+
)
8+
9+
funcTestSolution(t*testing.T) {
10+
//测试用例
11+
cases:= []struct {
12+
namestring
13+
inputsstring
14+
expectbool
15+
}{
16+
{"TestCase","PPALLP",true},
17+
{"TestCase","PPALLL",false},
18+
}
19+
20+
//开始测试
21+
fori,c:=rangecases {
22+
t.Run(c.name+" "+strconv.Itoa(i),func(t*testing.T) {
23+
got:=checkRecord(c.inputs)
24+
if!reflect.DeepEqual(got,c.expect) {
25+
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
26+
c.expect,got,c.inputs)
27+
}
28+
})
29+
}
30+
}
31+
32+
//压力测试
33+
funcBenchmarkSolution(b*testing.B) {
34+
35+
}
36+
37+
//使用案列
38+
funcExampleSolution() {
39+
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp