File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed
solution/2300-2399/2309.Greatest English Letter in Upper and Lower Case Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,29 @@ function greatestLetter(s: string): string {
162
162
}
163
163
```
164
164
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
+
165
188
### ** ...**
166
189
167
190
```
Original file line number Diff line number Diff line change @@ -149,6 +149,29 @@ function greatestLetter(s: string): string {
149
149
}
150
150
```
151
151
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
+
152
175
### ** ...**
153
176
154
177
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments