Skip to content

Latest commit

 

History

History
83 lines (69 loc) · 2.07 KB

_2678. Number of Senior Citizens.md

File metadata and controls

83 lines (69 loc) · 2.07 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : May 22, 2024

Last updated : August 01, 2024


Related Topics : Array, String

Acceptance Rate : 81.45 %


Solutions

C

int countSeniors(char ** details, int detailsSize){
    int output = 0;
    for (int i = 0; i < detailsSize; i++) {
        if ((details[i][11] - '0') * 10 + details[i][12] - '0' > 60) {
            output++;
        }
    }
    return output;
}

Python

class Solution:
    def countSeniors(self, details: List[str]) -> int:
        counter = 0
        for detail in details :
            if int(detail[11:13]) > 60 :
                counter += 1
        return counter
class Solution:
    def countSeniors(self, details: List[str]) -> int:
        return sum([int(x[11:13]) > 60 for x in details])
class Solution:
    def countSeniors(self, details: List[str]) -> int:
        return [True for x in details if int(x[11:13]) > 60].count(True)

Java

class Solution {
    public int countSeniors(String[] details) {
        int counter = 0;
        for (String str : details) {
            if (Integer.parseInt(str.substring(11,13)) > 60) {
                counter++;
            }
        }
        return counter;
    }
}