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