{"id":216,"date":"2018-09-07T19:38:30","date_gmt":"2018-09-07T11:38:30","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=216"},"modified":"2018-11-29T14:39:26","modified_gmt":"2018-11-29T06:39:26","slug":"771-jewels-and-stones","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=216","title":{"rendered":"771. Jewels and Stones"},"content":{"rendered":"<p>You&#8217;re given strings\u00a0<code>J<\/code>\u00a0representing the types of stones that are jewels, and\u00a0<code>S<\/code>\u00a0representing the stones you have.\u00a0 Each character in\u00a0<code>S<\/code>\u00a0is a type of stone you have.\u00a0 You want to know how many of the stones you have are also jewels.<\/p>\n<p>The letters in\u00a0<code>J<\/code>\u00a0are guaranteed distinct, and all characters in\u00a0<code>J<\/code>\u00a0and\u00a0<code>S<\/code>\u00a0are letters. Letters are case sensitive, so\u00a0<code>\"a\"<\/code>\u00a0is considered a different type of stone from\u00a0<code>\"A\"<\/code>.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong> J = \"aA\", S = \"aAAbbbb\"\r\n<strong>Output:<\/strong> 3\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong> J = \"z\", S = \"ZZ\"\r\n<strong>Output:<\/strong> 0\r\n<\/pre>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li><code>S<\/code>\u00a0and\u00a0<code>J<\/code>\u00a0will consist of letters and have length at most 50.<\/li>\n<li>The characters in\u00a0<code>J<\/code>\u00a0are distinct.<\/li>\n<\/ul>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def numJewelsInStones(self, J, S):\r\n        &quot;&quot;&quot;\r\n        :type J: str\r\n        :type S: str\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        jdict = {}\r\n        for i in J:\r\n            jdict[i] = 1\r\n        result = 0\r\n        for i in S:\r\n            result += jdict.get(i, 0)\r\n        return result\r\n            \r\n        \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;re given strings\u00a0J\u00a0representing the types of <a href=\"https:\/\/www.ccagml.com\/?p=216\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">771. Jewels and Stones<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/216"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":217,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/216\/revisions\/217"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}