File tree Expand file tree Collapse file tree 4 files changed +134
-0
lines changed
solution/0700-0799/0784.Letter Case Permutation Expand file tree Collapse file tree 4 files changed +134
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,54 @@ func letterCasePermutation(s string) []string {
151
151
}
152
152
```
153
153
154
+ ### ** TypeScript**
155
+
156
+ ``` ts
157
+ function letterCasePermutation(s : string ): string [] {
158
+ const n = s .length ;
159
+ const cs = [... s ];
160
+ const res = [];
161
+ const dfs = (i : number ) => {
162
+ if (i === n ) {
163
+ res .push (cs .join (' ' ));
164
+ return ;
165
+ }
166
+ dfs (i + 1 );
167
+ if (cs [i ] >= ' A' ) {
168
+ cs [i ] = String .fromCharCode (cs [i ].charCodeAt (0 ) ^ 32 );
169
+ dfs (i + 1 );
170
+ }
171
+ };
172
+ dfs (0 );
173
+ return res ;
174
+ }
175
+ ```
176
+
177
+ ### ** Rust**
178
+
179
+ ``` rust
180
+ impl Solution {
181
+ fn dfs (i : usize , cs : & mut Vec <char >, res : & mut Vec <String >) {
182
+ if i == cs . len () {
183
+ res . push (cs . iter (). collect ());
184
+ return ;
185
+ }
186
+ Self :: dfs (i + 1 , cs , res );
187
+ if cs [i ] >= 'A' {
188
+ cs [i ] = char :: from ((cs [i ] as u8 ) ^ 32 );
189
+ Self :: dfs (i + 1 , cs , res );
190
+ }
191
+ }
192
+
193
+ pub fn letter_case_permutation (s : String ) -> Vec <String > {
194
+ let mut res = Vec :: new ();
195
+ let mut cs = s . chars (). collect :: <Vec <char >>();
196
+ Self :: dfs (0 , & mut cs , & mut res );
197
+ res
198
+ }
199
+ }
200
+ ```
201
+
154
202
### ** ...**
155
203
156
204
```
Original file line number Diff line number Diff line change @@ -133,6 +133,54 @@ func letterCasePermutation(s string) []string {
133
133
}
134
134
```
135
135
136
+ ### ** TypeScript**
137
+
138
+ ``` ts
139
+ function letterCasePermutation(s : string ): string [] {
140
+ const n = s .length ;
141
+ const cs = [... s ];
142
+ const res = [];
143
+ const dfs = (i : number ) => {
144
+ if (i === n ) {
145
+ res .push (cs .join (' ' ));
146
+ return ;
147
+ }
148
+ dfs (i + 1 );
149
+ if (cs [i ] >= ' A' ) {
150
+ cs [i ] = String .fromCharCode (cs [i ].charCodeAt (0 ) ^ 32 );
151
+ dfs (i + 1 );
152
+ }
153
+ };
154
+ dfs (0 );
155
+ return res ;
156
+ }
157
+ ```
158
+
159
+ ### ** Rust**
160
+
161
+ ``` rust
162
+ impl Solution {
163
+ fn dfs (i : usize , cs : & mut Vec <char >, res : & mut Vec <String >) {
164
+ if i == cs . len () {
165
+ res . push (cs . iter (). collect ());
166
+ return ;
167
+ }
168
+ Self :: dfs (i + 1 , cs , res );
169
+ if cs [i ] >= 'A' {
170
+ cs [i ] = char :: from ((cs [i ] as u8 ) ^ 32 );
171
+ Self :: dfs (i + 1 , cs , res );
172
+ }
173
+ }
174
+
175
+ pub fn letter_case_permutation (s : String ) -> Vec <String > {
176
+ let mut res = Vec :: new ();
177
+ let mut cs = s . chars (). collect :: <Vec <char >>();
178
+ Self :: dfs (0 , & mut cs , & mut res );
179
+ res
180
+ }
181
+ }
182
+ ```
183
+
136
184
### ** ...**
137
185
138
186
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ fn dfs ( i : usize , cs : & mut Vec < char > , res : & mut Vec < String > ) {
3
+ if i == cs. len ( ) {
4
+ res. push ( cs. iter ( ) . collect ( ) ) ;
5
+ return ;
6
+ }
7
+ Self :: dfs ( i + 1 , cs, res) ;
8
+ if cs[ i] >= 'A' {
9
+ cs[ i] = char:: from ( ( cs[ i] as u8 ) ^ 32 ) ;
10
+ Self :: dfs ( i + 1 , cs, res) ;
11
+ }
12
+ }
13
+
14
+ pub fn letter_case_permutation ( s : String ) -> Vec < String > {
15
+ let mut res = Vec :: new ( ) ;
16
+ let mut cs = s. chars ( ) . collect :: < Vec < char > > ( ) ;
17
+ Self :: dfs ( 0 , & mut cs, & mut res) ;
18
+ res
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ function letterCasePermutation ( s : string ) : string [ ] {
2
+ const n = s . length ;
3
+ const cs = [ ...s ] ;
4
+ const res = [ ] ;
5
+ const dfs = ( i : number ) => {
6
+ if ( i === n ) {
7
+ res . push ( cs . join ( '' ) ) ;
8
+ return ;
9
+ }
10
+ dfs ( i + 1 ) ;
11
+ if ( cs [ i ] >= 'A' ) {
12
+ cs [ i ] = String . fromCharCode ( cs [ i ] . charCodeAt ( 0 ) ^ 32 ) ;
13
+ dfs ( i + 1 ) ;
14
+ }
15
+ } ;
16
+ dfs ( 0 ) ;
17
+ return res ;
18
+ }
You can’t perform that action at this time.
0 commit comments