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 e4ba68b

Browse files
authored
feat: add rust solution to lc problem: No.2586 (doocs#1177)
Signed-off-by: xiaolatiao <1628652790@qq.com>
1 parent fff7ed1 commit e4ba68b

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

‎solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,30 @@ function vowelStrings(words: string[], left: number, right: number): number {
150150
}
151151
```
152152

153+
### **Rust**
154+
155+
```rust
156+
impl Solution {
157+
pub fn vowel_strings(words: Vec<String>, left: i32, right: i32) -> i32 {
158+
let check = |c: u8| -> bool {
159+
c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u'
160+
};
161+
162+
let mut ans = 0;
163+
for i in left..=right {
164+
let words_bytes = words[i as usize].as_bytes();
165+
let first_char = words_bytes[0];
166+
let last_char = words_bytes[words_bytes.len() - 1];
167+
if check(first_char) && check(last_char) {
168+
ans += 1;
169+
}
170+
}
171+
172+
ans
173+
}
174+
}
175+
```
176+
153177
### **...**
154178

155179
```

‎solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@ function vowelStrings(words: string[], left: number, right: number): number {
140140
}
141141
```
142142

143+
### **Rust**
144+
145+
```rust
146+
impl Solution {
147+
pub fn vowel_strings(words: Vec<String>, left: i32, right: i32) -> i32 {
148+
let check = |c: u8| -> bool {
149+
c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u'
150+
};
151+
152+
let mut ans = 0;
153+
for i in left..=right {
154+
let words_bytes = words[i as usize].as_bytes();
155+
let first_char = words_bytes[0];
156+
let last_char = words_bytes[words_bytes.len() - 1];
157+
if check(first_char) && check(last_char) {
158+
ans += 1;
159+
}
160+
}
161+
162+
ans
163+
}
164+
}
165+
```
166+
143167
### **...**
144168

145169
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
impl Solution {
2+
pub fn vowel_strings(words: Vec<String>, left: i32, right: i32) -> i32 {
3+
let check = |c: u8| -> bool {
4+
c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u'
5+
};
6+
7+
let mut ans = 0;
8+
for i in left..=right {
9+
let words_bytes = words[i as usize].as_bytes();
10+
let first_char = words_bytes[0];
11+
let last_char = words_bytes[words_bytes.len() - 1];
12+
if check(first_char) && check(last_char) {
13+
ans += 1;
14+
}
15+
}
16+
17+
ans
18+
}
19+
}

0 commit comments

Comments
(0)

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