Skip to content

Commit

Permalink
Merge pull request #946 from 0xff-dev/2678
Browse files Browse the repository at this point in the history
Add solution and test-cases for problem 2678
  • Loading branch information
6boris authored Sep 9, 2024
2 parents 1bb2eae + ebcb188 commit fc3797e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
34 changes: 34 additions & 0 deletions leetcode/2601-2700/2678.Number-of-Senior-Citizens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# [2678.Number of Senior Citizens][title]

## Description
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:

- The first ten characters consist of the phone number of passengers.
- The next character denotes the gender of the person.
- The following two characters are used to indicate the age of the person.
- The last two characters determine the seat allotted to that person.

Return the number of passengers who are **strictly more than 60 years old**.

**Example 1:**

```
Input: details = ["7868190130M7522","5303914400F9211","9273338290F4010"]
Output: 2
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.
```

**Example 2:**

```
Input: details = ["1313579440F2036","2921522980M5644"]
Output: 0
Explanation: None of the passengers are older than 60.
```

## 结语

如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-algorithm][me]

[title]: https://leetcode.com/problems/number-of-senior-citizens
[me]: https://github.com/kylesliu/awesome-golang-algorithm
13 changes: 11 additions & 2 deletions leetcode/2601-2700/2678.Number-of-Senior-Citizens/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package Solution

func Solution(x bool) bool {
return x
import "strconv"

func Solution(details []string) int {
ans := 0
for _, d := range details {
age, _ := strconv.Atoi(d[11:13])
if age > 60 {
ans++
}
}
return ans
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs []string
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []string{"7868190130M7522", "5303914400F9211", "9273338290F4010"}, 2},
{"TestCase2", []string{"1313579440F2036", "2921522980M5644"}, 0},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}

0 comments on commit fc3797e

Please sign in to comment.