File tree 3 files changed +79
-0
lines changed
solution/2600-2699/2678.Number of Senior Citizens
3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,38 @@ func countSeniors(details []string) (ans int) {
120
120
}
121
121
```
122
122
123
+ ### ** Rust**
124
+
125
+ ``` rust
126
+ impl Solution {
127
+ pub fn count_seniors (details : Vec <String >) -> i32 {
128
+ let mut ans = 0 ;
129
+
130
+ for s in details . iter () {
131
+ if let Ok (age ) = s [11 .. 13 ]. parse :: <i32 >() {
132
+ if age > 60 {
133
+ ans += 1 ;
134
+ }
135
+ }
136
+ }
137
+
138
+ ans
139
+ }
140
+ }
141
+ ```
142
+
143
+ ``` rust
144
+ impl Solution {
145
+ pub fn count_seniors (details : Vec <String >) -> i32 {
146
+ details
147
+ . iter ()
148
+ . filter_map (| s | s [11 .. 13 ]. parse :: <i32 >(). ok ())
149
+ . filter (| & age | age > 60 )
150
+ . count () as i32
151
+ }
152
+ }
153
+ ```
154
+
123
155
### ** ...**
124
156
125
157
```
Original file line number Diff line number Diff line change @@ -102,6 +102,38 @@ func countSeniors(details []string) (ans int) {
102
102
}
103
103
```
104
104
105
+ ### ** Rust**
106
+
107
+ ``` rust
108
+ impl Solution {
109
+ pub fn count_seniors (details : Vec <String >) -> i32 {
110
+ let mut ans = 0 ;
111
+
112
+ for s in details . iter () {
113
+ if let Ok (age ) = s [11 .. 13 ]. parse :: <i32 >() {
114
+ if age > 60 {
115
+ ans += 1 ;
116
+ }
117
+ }
118
+ }
119
+
120
+ ans
121
+ }
122
+ }
123
+ ```
124
+
125
+ ``` rust
126
+ impl Solution {
127
+ pub fn count_seniors (details : Vec <String >) -> i32 {
128
+ details
129
+ . iter ()
130
+ . filter_map (| s | s [11 .. 13 ]. parse :: <i32 >(). ok ())
131
+ . filter (| & age | age > 60 )
132
+ . count () as i32
133
+ }
134
+ }
135
+ ```
136
+
105
137
### ** ...**
106
138
107
139
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn count_seniors ( details : Vec < String > ) -> i32 {
3
+ let mut ans = 0 ;
4
+
5
+ for s in details. iter ( ) {
6
+ if let Ok ( age) = s[ 11 ..13 ] . parse :: < i32 > ( ) {
7
+ if age > 60 {
8
+ ans += 1 ;
9
+ }
10
+ }
11
+ }
12
+
13
+ ans
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments