LeetCode 771

  1. Create a new hash
  2. Initialize a counter equal to 0
  3. Set the hash with elements in the Jewels string.
  4. Iterate over the Stones string and determine if current iteration is in the Hash. If it is, increment a counter
  5. Return the counter
var numJewelsInStones = function(jewels, stones) {
//step 1
let hash = new Map()
//step 2
let count = 0
//step 3
for (let ele of jewels) {
hash.set(ele, ele)
}
//step 4
for (let i=0; i < stones.length; i++) {
if (hash.get(stones[i])) {
count++
}
}
//step 5
return count
};
let count = 0
for (let ele of jewels) {
hash.set(ele, ele)
}

for (let i=0; i < stones.length; i++) {
if (hash.get(stones[i])) {
count++
}
}
return count
};

Flatiron student, word nerd and otter enthusiast

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Open Letter to Our Community

How Do Companies Measure Cybersecurity Risks?

New Airdrop: Privapp Network (PRIVA) Reward: 15 PRIVA Rate: ⭐️⭐️⭐️⭐️ Focus: Distribution starts…

APWG Phishing Activity Trends Reports for Q3’19 Raise Alarm

DRF Airdrop : Derify Beta Testnet On Binance Smart Chain

Earning Bounties: An Introduction to OpenSea’s Affiliate Program

Lean Data Practices: Helping Businesses and Developers be more Privacy Aware

Working in Cyber Security: “Security is a mindset, not a series of courses or a test you passed”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Crystal Villanueva

Crystal Villanueva

Flatiron student, word nerd and otter enthusiast

More from Medium

Use of the Stack Data Structure and it’s Applications

Feature scaling

[Engineering] Computer Vision in Hackathon Journey

Kruskal’s Algorithm — A Summary