mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加(0242.有效的字母异位词.md):增加typescript版本
This commit is contained in:
@ -214,7 +214,23 @@ var isAnagram = function(s, t) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
TypeScript:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
function isAnagram(s: string, t: string): boolean {
|
||||||
|
if (s.length !== t.length) return false;
|
||||||
|
let helperArr: number[] = new Array(26).fill(0);
|
||||||
|
let pivot: number = 'a'.charCodeAt(0);
|
||||||
|
for (let i = 0, length = s.length; i < length; i++) {
|
||||||
|
helperArr[s.charCodeAt(i) - pivot]++;
|
||||||
|
helperArr[t.charCodeAt(i) - pivot]--;
|
||||||
|
}
|
||||||
|
return helperArr.every(i => i === 0);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
Swift:
|
Swift:
|
||||||
|
|
||||||
```Swift
|
```Swift
|
||||||
func isAnagram(_ s: String, _ t: String) -> Bool {
|
func isAnagram(_ s: String, _ t: String) -> Bool {
|
||||||
if s.count != t.count {
|
if s.count != t.count {
|
||||||
|
Reference in New Issue
Block a user