File tree 3 files changed +61
-0
lines changed
solution/1100-1199/1153.String Transforms Into Another String
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,28 @@ func canConvert(str1 string, str2 string) bool {
174
174
}
175
175
```
176
176
177
+ ### ** TypeScript**
178
+
179
+ ``` ts
180
+ function canConvert(str1 : string , str2 : string ): boolean {
181
+ if (str1 === str2 ) {
182
+ return true ;
183
+ }
184
+ if (new Set (str2 ).size === 26 ) {
185
+ return false ;
186
+ }
187
+ const d: Map <string , string > = new Map ();
188
+ for (const [i, c] of str1 .split (' ' ).entries ()) {
189
+ if (! d .has (c )) {
190
+ d .set (c , str2 [i ]);
191
+ } else if (d .get (c ) !== str2 [i ]) {
192
+ return false ;
193
+ }
194
+ }
195
+ return true ;
196
+ }
197
+ ```
198
+
177
199
### ** ...**
178
200
179
201
```
Original file line number Diff line number Diff line change @@ -152,6 +152,28 @@ func canConvert(str1 string, str2 string) bool {
152
152
}
153
153
```
154
154
155
+ ### ** TypeScript**
156
+
157
+ ``` ts
158
+ function canConvert(str1 : string , str2 : string ): boolean {
159
+ if (str1 === str2 ) {
160
+ return true ;
161
+ }
162
+ if (new Set (str2 ).size === 26 ) {
163
+ return false ;
164
+ }
165
+ const d: Map <string , string > = new Map ();
166
+ for (const [i, c] of str1 .split (' ' ).entries ()) {
167
+ if (! d .has (c )) {
168
+ d .set (c , str2 [i ]);
169
+ } else if (d .get (c ) !== str2 [i ]) {
170
+ return false ;
171
+ }
172
+ }
173
+ return true ;
174
+ }
175
+ ```
176
+
155
177
### ** ...**
156
178
157
179
```
Original file line number Diff line number Diff line change
1
+ function canConvert ( str1 : string , str2 : string ) : boolean {
2
+ if ( str1 === str2 ) {
3
+ return true ;
4
+ }
5
+ if ( new Set ( str2 ) . size === 26 ) {
6
+ return false ;
7
+ }
8
+ const d : Map < string , string > = new Map ( ) ;
9
+ for ( const [ i , c ] of str1 . split ( '' ) . entries ( ) ) {
10
+ if ( ! d . has ( c ) ) {
11
+ d . set ( c , str2 [ i ] ) ;
12
+ } else if ( d . get ( c ) !== str2 [ i ] ) {
13
+ return false ;
14
+ }
15
+ }
16
+ return true ;
17
+ }
You can’t perform that action at this time.
0 commit comments