mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
update242.有效的字母异位词
This commit is contained in:
@ -143,17 +143,23 @@ func isAnagram(s string, t string) bool {
|
||||
javaScript:
|
||||
|
||||
```js
|
||||
/**
|
||||
* @param {string} s
|
||||
* @param {string} t
|
||||
* @return {boolean}
|
||||
*/
|
||||
var isAnagram = function(s, t) {
|
||||
const resSet = new Array(25).fill(0);
|
||||
if(s.length !== t.length) return false;
|
||||
const resSet = new Array(26).fill(0);
|
||||
const base = "a".charCodeAt();
|
||||
for(const i of s) {
|
||||
resSet[i.charCodeAt() - base]++;
|
||||
}
|
||||
for(const i of t) {
|
||||
if(!resSet[i.charCodeAt() - base]) return false;
|
||||
resSet[i.charCodeAt() - base]--;
|
||||
// if(val < 0) return false;
|
||||
}
|
||||
return resSet.every(i => !i);
|
||||
return true;
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -176,7 +176,7 @@ javaScript:
|
||||
* @return {boolean}
|
||||
*/
|
||||
var canConstruct = function(ransomNote, magazine) {
|
||||
const strArr = new Array(25).fill(0),
|
||||
const strArr = new Array(26).fill(0),
|
||||
base = "a".charCodeAt();
|
||||
for(const s of magazine) {
|
||||
strArr[s.charCodeAt() - base]++;
|
||||
|
Reference in New Issue
Block a user