-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #946 from 0xff-dev/2678
Add solution and test-cases for problem 2678
- Loading branch information
Showing
3 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
leetcode/2601-2700/2678.Number-of-Senior-Citizens/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
leetcode/2601-2700/2678.Number-of-Senior-Citizens/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters