{"id":9157,"date":"2021-12-12T15:08:22","date_gmt":"2021-12-12T23:08:22","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=9157"},"modified":"2021-12-12T15:10:48","modified_gmt":"2021-12-12T23:10:48","slug":"leetcode-2103-rings-and-rods","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/hashtable\/leetcode-2103-rings-and-rods\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 2103. Rings and Rods"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.com\/problems\/rings-and-rods\/\">Problem<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Hashset<\/strong><\/h2>\n\n\n\n<p>Use 10 hashsets to track the status of each rod, check whether it contains three unique elements (R,G,B).<\/p>\n\n\n\n<p>Time complexity: O(n)<br>Space complexity: O(10*3)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  int countPoints(string rings) {\n    constexpr int kRods = 10;\n    vector<unordered_set<char>> s(kRods);\n    for (int i = 0; i < rings.size(); i += 2)      \n      s[rings[i + 1] - '0'].insert(rings[i]);\n    int ans = 0;\n    for (int i = 0; i < kRods; ++i)\n      if (s[i].size() == 3)\n        ++ans;\n    return ans;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Problem Solution: Hashset Use 10 hashsets to track the status of each rod, check whether it contains three unique elements (R,G,B). Time complexity: O(n)Space complexity:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[222,299,4],"class_list":["post-9157","post","type-post","status-publish","format-standard","hentry","category-hashtable","tag-easy","tag-hashset","tag-string","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=9157"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9157\/revisions"}],"predecessor-version":[{"id":9161,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9157\/revisions\/9161"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=9157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=9157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=9157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}