diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md index 527945fa..7ff28601 100644 --- a/problems/0383.赎金信.md +++ b/problems/0383.赎金信.md @@ -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; +}; +```