Skip to content

Commit 92c507b

Browse files
Merge pull request youngyangyang04#1013 from xiaofei-2020/hash2
添加(0242.有效的字母异位词.md):增加typescript版本
2 parents 4a3ea4c + 21fc5cd commit 92c507b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

problems/0242.有效的字母异位词.md

+16
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,23 @@ var isAnagram = function(s, t) {
214214
};
215215
```
216216

217+
TypeScript:
218+
219+
```typescript
220+
function isAnagram(s: string, t: string): boolean {
221+
if (s.length !== t.length) return false;
222+
let helperArr: number[] = new Array(26).fill(0);
223+
let pivot: number = 'a'.charCodeAt(0);
224+
for (let i = 0, length = s.length; i < length; i++) {
225+
helperArr[s.charCodeAt(i) - pivot]++;
226+
helperArr[t.charCodeAt(i) - pivot]--;
227+
}
228+
return helperArr.every(i => i === 0);
229+
};
230+
```
231+
217232
Swift:
233+
218234
```Swift
219235
func isAnagram(_ s: String, _ t: String) -> Bool {
220236
if s.count != t.count {

0 commit comments

Comments
 (0)