Skip to content

Commit fc3797e

Browse files
authored
Merge pull request #946 from 0xff-dev/2678
Add solution and test-cases for problem 2678
2 parents 1bb2eae + ebcb188 commit fc3797e

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [2678.Number of Senior Citizens][title]
2+
3+
## Description
4+
You are given a **0-indexed** array of strings `details`. Each element of `details` provides information about a given passenger compressed into a string of length `15`. The system is such that:
5+
6+
- The first ten characters consist of the phone number of passengers.
7+
- The next character denotes the gender of the person.
8+
- The following two characters are used to indicate the age of the person.
9+
- The last two characters determine the seat allotted to that person.
10+
11+
Return the number of passengers who are **strictly more than 60 years old**.
12+
13+
**Example 1:**
14+
15+
```
16+
Input: details = ["7868190130M7522","5303914400F9211","9273338290F4010"]
17+
Output: 2
18+
Explanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.
19+
```
20+
21+
**Example 2:**
22+
23+
```
24+
Input: details = ["1313579440F2036","2921522980M5644"]
25+
Output: 0
26+
Explanation: None of the passengers are older than 60.
27+
```
28+
29+
## 结语
30+
31+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-algorithm][me]
32+
33+
[title]: https://leetcode.com/problems/number-of-senior-citizens
34+
[me]: https://github.com/kylesliu/awesome-golang-algorithm
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
import "strconv"
4+
5+
func Solution(details []string) int {
6+
ans := 0
7+
for _, d := range details {
8+
age, _ := strconv.Atoi(d[11:13])
9+
if age > 60 {
10+
ans++
11+
}
12+
}
13+
return ans
514
}

leetcode/2601-2700/2678.Number-of-Senior-Citizens/Solution_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs []string
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", []string{"7868190130M7522", "5303914400F9211", "9273338290F4010"}, 2},
17+
{"TestCase2", []string{"1313579440F2036", "2921522980M5644"}, 0},
1918
}
2019

2120
// 开始测试
@@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)