[LeetCode] Number of Senior Citizens

2678. Number of Senior Citizens

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.

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int countSeniors(vector<string>& details) {
int res = 0;
for(auto d : details) {
int age = (d[11] - '0') * 10 + d[12] - '0';
res += age > 60;
}
return res;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/13/PS/LeetCode/number-of-senior-citizens/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.