mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加(0205.同构字符串.md):增加typescript版本
This commit is contained in:
@ -156,6 +156,28 @@ var isIsomorphic = function(s, t) {
|
||||
};
|
||||
```
|
||||
|
||||
## TypeScript
|
||||
|
||||
```typescript
|
||||
function isIsomorphic(s: string, t: string): boolean {
|
||||
const helperMap1: Map<string, string> = new Map();
|
||||
const helperMap2: Map<string, string> = new Map();
|
||||
for (let i = 0, length = s.length; i < length; i++) {
|
||||
let temp1: string | undefined = helperMap1.get(s[i]);
|
||||
let temp2: string | undefined = helperMap2.get(t[i]);
|
||||
if (temp1 === undefined && temp2 === undefined) {
|
||||
helperMap1.set(s[i], t[i]);
|
||||
helperMap2.set(t[i], s[i]);
|
||||
} else if (temp1 !== t[i] || temp2 !== s[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user