作者:
Rushia (みけねこ的鼻屎)
2022-11-30 09:20:231207. Unique Number of Occurrences
給予一個整數陣列,若該整數的每個數字出現次數都不重複返回true,否則false。
Example:
Input: arr = [1,2,2,1,1,3]
Output: true
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two
values have the same number of occurrences.
Input: arr = [1,2]
Output: false
思路:
1.用HashMap統計每個數字的出現次數
2.用Set檢查出現次數是否重複
JavaCode: