File tree Expand file tree Collapse file tree 7 files changed +190
-0
lines changed
0700-0799/0709.To Lower Case
1300-1399/1309.Decrypt String from Alphabet to Integer Mapping Expand file tree Collapse file tree 7 files changed +190
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,30 @@ func toLowerCase(s string) string {
106
106
}
107
107
```
108
108
109
+ ### ** Rust**
110
+
111
+ ``` rust
112
+ impl Solution {
113
+ pub fn to_lower_case (s : String ) -> String {
114
+ s . to_ascii_lowercase ()
115
+ }
116
+ }
117
+ ```
118
+
119
+ ``` rust
120
+ impl Solution {
121
+ pub fn to_lower_case (s : String ) -> String {
122
+ String :: from_utf8 (
123
+ s . as_bytes ()
124
+ . iter ()
125
+ . map (| & c | c + if c >= b 'A' && c <= b 'Z' { 32 } else { 0 })
126
+ . collect (),
127
+ )
128
+ . unwrap ()
129
+ }
130
+ }
131
+ ```
132
+
109
133
### ** ...**
110
134
111
135
```
Original file line number Diff line number Diff line change @@ -94,6 +94,30 @@ func toLowerCase(s string) string {
94
94
}
95
95
```
96
96
97
+ ### ** Rust**
98
+
99
+ ``` rust
100
+ impl Solution {
101
+ pub fn to_lower_case (s : String ) -> String {
102
+ s . to_ascii_lowercase ()
103
+ }
104
+ }
105
+ ```
106
+
107
+ ``` rust
108
+ impl Solution {
109
+ pub fn to_lower_case (s : String ) -> String {
110
+ String :: from_utf8 (
111
+ s . as_bytes ()
112
+ . iter ()
113
+ . map (| & c | c + if c >= b 'A' && c <= b 'Z' { 32 } else { 0 })
114
+ . collect (),
115
+ )
116
+ . unwrap ()
117
+ }
118
+ }
119
+ ```
120
+
97
121
### ** ...**
98
122
99
123
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn to_lower_case ( s : String ) -> String {
3
+ String :: from_utf8 (
4
+ s. as_bytes ( )
5
+ . iter ( )
6
+ . map ( |& c| c + if c >= b'A' && c <= b'Z' { 32 } else { 0 } )
7
+ . collect ( ) ,
8
+ )
9
+ . unwrap ( )
10
+ }
11
+ }
Original file line number Diff line number Diff line change @@ -109,6 +109,53 @@ class Solution {
109
109
}
110
110
```
111
111
112
+ ### ** TypeScript**
113
+
114
+ ``` ts
115
+ function freqAlphabets(s : string ): string {
116
+ const n = s .length ;
117
+ const res = [];
118
+ let i = 0 ;
119
+ while (i < n ) {
120
+ let code: string ;
121
+ if (s [i + 2 ] === ' #' ) {
122
+ code = s .slice (i , i + 2 );
123
+ i += 3 ;
124
+ } else {
125
+ code = s [i ];
126
+ i += 1 ;
127
+ }
128
+ res .push (code );
129
+ }
130
+ return res .map (v => String .fromCharCode (96 + Number (v ))).join (' ' );
131
+ }
132
+ ```
133
+
134
+ ### ** Rust**
135
+
136
+ ``` rust
137
+ impl Solution {
138
+ pub fn freq_alphabets (s : String ) -> String {
139
+ let s = s . as_bytes ();
140
+ let n = s . len ();
141
+ let mut res = String :: new ();
142
+ let mut i = 0 ;
143
+ while i < n {
144
+ let code : u8 ;
145
+ if s . get (i + 2 ). is_some () && s [i + 2 ] == b '#' {
146
+ code = (s [i ] - b '0' ) * 10 + s [i + 1 ];
147
+ i += 3 ;
148
+ } else {
149
+ code = s [i ];
150
+ i += 1 ;
151
+ }
152
+ res . push (char :: from (97 + code - b '1' ));
153
+ }
154
+ res
155
+ }
156
+ }
157
+ ```
158
+
112
159
### ** ...**
113
160
114
161
```
Original file line number Diff line number Diff line change @@ -89,6 +89,53 @@ class Solution {
89
89
}
90
90
```
91
91
92
+ ### ** TypeScript**
93
+
94
+ ``` ts
95
+ function freqAlphabets(s : string ): string {
96
+ const n = s .length ;
97
+ const res = [];
98
+ let i = 0 ;
99
+ while (i < n ) {
100
+ let code: string ;
101
+ if (s [i + 2 ] === ' #' ) {
102
+ code = s .slice (i , i + 2 );
103
+ i += 3 ;
104
+ } else {
105
+ code = s [i ];
106
+ i += 1 ;
107
+ }
108
+ res .push (code );
109
+ }
110
+ return res .map (v => String .fromCharCode (96 + Number (v ))).join (' ' );
111
+ }
112
+ ```
113
+
114
+ ### ** Rust**
115
+
116
+ ``` rust
117
+ impl Solution {
118
+ pub fn freq_alphabets (s : String ) -> String {
119
+ let s = s . as_bytes ();
120
+ let n = s . len ();
121
+ let mut res = String :: new ();
122
+ let mut i = 0 ;
123
+ while i < n {
124
+ let code : u8 ;
125
+ if s . get (i + 2 ). is_some () && s [i + 2 ] == b '#' {
126
+ code = (s [i ] - b '0' ) * 10 + s [i + 1 ];
127
+ i += 3 ;
128
+ } else {
129
+ code = s [i ];
130
+ i += 1 ;
131
+ }
132
+ res . push (char :: from (97 + code - b '1' ));
133
+ }
134
+ res
135
+ }
136
+ }
137
+ ```
138
+
92
139
### ** ...**
93
140
94
141
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn freq_alphabets ( s : String ) -> String {
3
+ let s = s. as_bytes ( ) ;
4
+ let n = s. len ( ) ;
5
+ let mut res = String :: new ( ) ;
6
+ let mut i = 0 ;
7
+ while i < n {
8
+ let code: u8 ;
9
+ if s. get ( i + 2 ) . is_some ( ) && s[ i + 2 ] == b'#' {
10
+ code = ( s[ i] - b'0' ) * 10 + s[ i + 1 ] ;
11
+ i += 3 ;
12
+ } else {
13
+ code = s[ i] ;
14
+ i += 1 ;
15
+ }
16
+ res. push ( char:: from ( 97 + code - b'1' ) ) ;
17
+ }
18
+ res
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ function freqAlphabets ( s : string ) : string {
2
+ const n = s . length ;
3
+ const res = [ ] ;
4
+ let i = 0 ;
5
+ while ( i < n ) {
6
+ let code : string ;
7
+ if ( s [ i + 2 ] === '#' ) {
8
+ code = s . slice ( i , i + 2 ) ;
9
+ i += 3 ;
10
+ } else {
11
+ code = s [ i ] ;
12
+ i += 1 ;
13
+ }
14
+ res . push ( code ) ;
15
+ }
16
+ return res . map ( v => String . fromCharCode ( 96 + Number ( v ) ) ) . join ( '' ) ;
17
+ }
You can’t perform that action at this time.
0 commit comments