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

Commit eb4927a

Browse files
feat: solve No.2678
1 parent eb625c2 commit eb4927a

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# 2678. Number of Senior Citizens
2+
3+
- Difficulty: Easy.
4+
- Related Topics: Array, String.
5+
- Similar Questions: .
6+
7+
## Problem
8+
9+
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:
10+
11+
12+
13+
- The first ten characters consist of the phone number of passengers.
14+
15+
- The next character denotes the gender of the person.
16+
17+
- The following two characters are used to indicate the age of the person.
18+
19+
- The last two characters determine the seat allotted to that person.
20+
21+
22+
Return **the number of passengers who are **strictly ****more than 60 years old**.**
23+
24+
25+
Example 1:
26+
27+
```
28+
Input: details = ["7868190130M7522","5303914400F9211","9273338290F4010"]
29+
Output: 2
30+
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.
31+
```
32+
33+
Example 2:
34+
35+
```
36+
Input: details = ["1313579440F2036","2921522980M5644"]
37+
Output: 0
38+
Explanation: None of the passengers are older than 60.
39+
```
40+
41+
42+
**Constraints:**
43+
44+
45+
46+
- `1 <= details.length <= 100`
47+
48+
- `details[i].length == 15`
49+
50+
- `details[i] consists of digits from '0' to '9'.`
51+
52+
- `details[i][10] is either 'M' or 'F' or 'O'.`
53+
54+
- The phone numbers and seat numbers of the passengers are distinct.
55+
56+
57+
58+
## Solution
59+
60+
```javascript
61+
/**
62+
* @param {string[]} details
63+
* @return {number}
64+
*/
65+
var countSeniors = function(details) {
66+
var count = 0;
67+
for (var i = 0; i < details.length; i++) {
68+
if (details[i][11] > '6' || (details[i][11] === '6' && details[i][12] > '0')) {
69+
count += 1;
70+
}
71+
}
72+
return count;
73+
};
74+
```
75+
76+
**Explain:**
77+
78+
nope.
79+
80+
**Complexity:**
81+
82+
* Time complexity : O(n).
83+
* Space complexity : O(1).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /