Skip to content

Commit 7c7fdd2

Browse files
committed
feat: add rust solution to lc problem: No.2309
No.2309.Greatest English Letter in Upper and Lower Case
1 parent c7cae77 commit 7c7fdd2

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ function greatestLetter(s: string): string {
162162
}
163163
```
164164

165+
### **Rust**
166+
167+
```rust
168+
impl Solution {
169+
pub fn greatest_letter(s: String) -> String {
170+
let mut arr = [0; 26];
171+
for &c in s.as_bytes().iter() {
172+
if c >= b'a' {
173+
arr[(c - b'a') as usize] |= 1;
174+
} else {
175+
arr[(c - b'A') as usize] |= 2;
176+
}
177+
}
178+
for i in (0..26).rev() {
179+
if arr[i] == 3 {
180+
return char::from(b'A' + i as u8).to_string();
181+
}
182+
}
183+
"".to_string()
184+
}
185+
}
186+
```
187+
165188
### **...**
166189

167190
```

solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case/README_EN.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,29 @@ function greatestLetter(s: string): string {
149149
}
150150
```
151151

152+
### **Rust**
153+
154+
```rust
155+
impl Solution {
156+
pub fn greatest_letter(s: String) -> String {
157+
let mut arr = [0; 26];
158+
for &c in s.as_bytes().iter() {
159+
if c >= b'a' {
160+
arr[(c - b'a') as usize] |= 1;
161+
} else {
162+
arr[(c - b'A') as usize] |= 2;
163+
}
164+
}
165+
for i in (0..26).rev() {
166+
if arr[i] == 3 {
167+
return char::from(b'A' + i as u8).to_string();
168+
}
169+
}
170+
"".to_string()
171+
}
172+
}
173+
```
174+
152175
### **...**
153176

154177
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
impl Solution {
2+
pub fn greatest_letter(s: String) -> String {
3+
let mut arr = [0; 26];
4+
for &c in s.as_bytes().iter() {
5+
if c >= b'a' {
6+
arr[(c - b'a') as usize] |= 1;
7+
} else {
8+
arr[(c - b'A') as usize] |= 2;
9+
}
10+
}
11+
for i in (0..26).rev() {
12+
if arr[i] == 3 {
13+
return char::from(b'A' + i as u8).to_string();
14+
}
15+
}
16+
"".to_string()
17+
}
18+
}

0 commit comments

Comments
 (0)