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

Calculating the cost of a data breach | Payatu

Data breaches: how to counter the costly matter

{UPDATE} Bubble Classic Hack Free Resources Generator

MY FIRST BOUNTY AS A BUG BOUNTY HUNTER (BUSINESS LOGIC)

Information Security in Business Owner Perspective

Information Security in Business Owner Perspective

{UPDATE} Money Clicker Hack Free Resources Generator

4 Security Tools you should consider

Why The Equifax Data Breach Is One Of The Worst Leaks

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

Big-O Notation — Put Simply

5 Reasons why Online Coding Assessments are Pointless

Encoding Using Greedy Algorithm: Huffman Coding

Linking Together Linked Lists