Skip to content

Commit bc3d202

Browse files
committed
添加(0205.同构字符串.md):增加typescript版本
1 parent be18cd3 commit bc3d202

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

problems/0205.同构字符串.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ var isIsomorphic = function(s, t) {
156156
};
157157
```
158158

159+
## TypeScript
160+
161+
```typescript
162+
function isIsomorphic(s: string, t: string): boolean {
163+
const helperMap1: Map<string, string> = new Map();
164+
const helperMap2: Map<string, string> = new Map();
165+
for (let i = 0, length = s.length; i < length; i++) {
166+
let temp1: string | undefined = helperMap1.get(s[i]);
167+
let temp2: string | undefined = helperMap2.get(t[i]);
168+
if (temp1 === undefined && temp2 === undefined) {
169+
helperMap1.set(s[i], t[i]);
170+
helperMap2.set(t[i], s[i]);
171+
} else if (temp1 !== t[i] || temp2 !== s[i]) {
172+
return false;
173+
}
174+
}
175+
return true;
176+
};
177+
```
178+
179+
180+
159181

160182
-----------------------
161183
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
 (0)