mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加383. 赎金信JavaScript版本
This commit is contained in:
@ -136,7 +136,7 @@ class Solution {
|
||||
```
|
||||
|
||||
Python:
|
||||
```
|
||||
```py
|
||||
class Solution(object):
|
||||
def canConstruct(self, ransomNote, magazine):
|
||||
"""
|
||||
@ -167,6 +167,28 @@ class Solution(object):
|
||||
|
||||
Go:
|
||||
|
||||
javaScript:
|
||||
|
||||
```js
|
||||
/**
|
||||
* @param {string} ransomNote
|
||||
* @param {string} magazine
|
||||
* @return {boolean}
|
||||
*/
|
||||
var canConstruct = function(ransomNote, magazine) {
|
||||
const strArr = new Array(25).fill(0),
|
||||
base = "a".charCodeAt();
|
||||
for(const s of magazine) {
|
||||
strArr[s.charCodeAt() - base]++;
|
||||
}
|
||||
for(const s of ransomNote) {
|
||||
const index = s.charCodeAt() - base;
|
||||
if(!strArr[index]) return false;
|
||||
strArr[index]--;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user