Skip to content

Commit 6ea09c2

Browse files
committed
feat: add solution to lc problem: No.1153
No.1153.String Transforms Into Another String
1 parent 0e3afae commit 6ea09c2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/1100-1199/1153.String Transforms Into Another String/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,28 @@ func canConvert(str1 string, str2 string) bool {
174174
}
175175
```
176176

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+
177199
### **...**
178200

179201
```

solution/1100-1199/1153.String Transforms Into Another String/README_EN.md

+22
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,28 @@ func canConvert(str1 string, str2 string) bool {
152152
}
153153
```
154154

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+
155177
### **...**
156178

157179
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)