Last active
December 30, 2020 18:04
-
-
Save ahmet-cetinkaya/a754c926d3ebf47f48c2b9cfc2cbe5eb to your computer and use it in GitHub Desktop.
LeetCode Solutions - 771. Jewels and Stones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numJewelsInStones = (J, S) => { | |
let c = 0; | |
for (let i = 0; i < S.length; ++i) if (J.indexOf(S[i]) > -1) ++c; | |
return c; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numJewelsInStones = (J, S) => S.split``.reduce((a, c) => a + J.includes(c), 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numJewelsInStones = (J, S) => { | |
const JSet = new Set(J); | |
return S.split``.reduce((a, c) => a + JSet.has(c), 0); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numJewelsInStones = (J, S) => (S.match(new RegExp(`[${J}]`, 'g')) || []).length; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jewelsAndStones.js
jewelsAndStones2.js
jewelsAndStones3.js
jewelsAndStones4.js