{"id":5591,"date":"2019-09-29T00:07:44","date_gmt":"2019-09-29T07:07:44","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=5591"},"modified":"2019-09-29T00:08:19","modified_gmt":"2019-09-29T07:08:19","slug":"leecode-1207-unique-number-of-occurrences","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/hashtable\/leecode-1207-unique-number-of-occurrences\/","title":{"rendered":"\u82b1\u82b1\u9171 LeeCode 1207. Unique Number of Occurrences"},"content":{"rendered":"\n<p>Given an array of integers&nbsp;<code>arr<\/code>,&nbsp;write a function that returns&nbsp;<code>true<\/code>&nbsp;if and only if the number of occurrences of each value in the array is unique.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> arr = [1,2,2,1,1,3]\n<strong>Output:<\/strong> true\n<strong>Explanation:<\/strong>&nbsp;The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> arr = [1,2]\n<strong>Output:<\/strong> false\n<\/pre>\n\n\n\n<p><strong>Example 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> arr = [-3,0,1,-3,1,1,1,-3,10,0]\n<strong>Output:<\/strong> true\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>1 &lt;= arr.length&nbsp;&lt;= 1000<\/code><\/li><li><code>-1000 &lt;= arr[i] &lt;= 1000<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: HashTable<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(n)<br>Space complexity: O(n)<\/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  bool uniqueOccurrences(vector<int>& arr) {\n    unordered_map<int, int> c;\n    for (int a : arr) ++c[a];\n    unordered_set<int> s;\n    for (const auto& kv : c)\n      if (!s.insert(kv.second).second) \n        return false;\n    return true;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given an array of integers&nbsp;arr,&nbsp;write a function that returns&nbsp;true&nbsp;if and only if the number of occurrences of each value in the array is unique. Example&#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,82],"class_list":["post-5591","post","type-post","status-publish","format-standard","hentry","category-hashtable","tag-easy","tag-hashtable","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5591","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=5591"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5591\/revisions"}],"predecessor-version":[{"id":5593,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5591\/revisions\/5593"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=5591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=5591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=5591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}