Created
June 19, 2019 21:38
-
-
Save restart916/393c4c7440042d8961c964928e00367b to your computer and use it in GitHub Desktop.
20190619_leetcode_771_JewelsandStones
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
/** | |
* @param {string} J | |
* @param {string} S | |
* @return {number} | |
*/ | |
var numJewelsInStones = function(J, S) { | |
let count = 0 | |
sMap = {} | |
for (let s of S) { | |
if (s in sMap) { | |
sMap[s]++; | |
} else { | |
sMap[s] = 1; | |
} | |
} | |
for (let j of J) { | |
if (j in sMap) { | |
count += sMap[j] | |
} | |
} | |
return count; | |
} |
호엥 이 풀이 보니까 제가 진짜 변태적으로 풀었다는 것은 잘 알겠네욬ㅋㅋㅋㅋㅋㅋㅋㅋ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
사실은.. 며칠전에 미리 풀어봤던 문제입니다.
당시에 풀이도 기록해 놓은게 있어서 같이 공유합니다.
https://restart916.github.io/posts/20190615_leetcode_771.html
저는 이 미리 map 으로 카운트 세놓고 더하는 풀이방식이 맘에들더라구요