|
| 1 | +<p>You are given an integer array <code>nums</code>.</p> |
| 2 | + |
| 3 | +<p>Return an integer denoting the <strong>first</strong> element (scanning from left to right) in <code>nums</code> whose <strong>frequency</strong> is <strong>unique</strong>. That is, no other integer appears the same number of times in <code>nums</code>. If there is no such element, return -1.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<div class="example-block"> |
| 9 | +<p><strong>Input:</strong> <span class="example-io">nums = [20,10,30,30]</span></p> |
| 10 | + |
| 11 | +<p><strong>Output:</strong> <span class="example-io">30</span></p> |
| 12 | + |
| 13 | +<p><strong>Explanation:</strong></p> |
| 14 | + |
| 15 | +<ul> |
| 16 | + <li>20 appears once.</li> |
| 17 | + <li>10 appears once.</li> |
| 18 | + <li>30 appears twice.</li> |
| 19 | + <li>The frequency of 30 is unique because no other integer appears exactly twice.</li> |
| 20 | +</ul> |
| 21 | +</div> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | + |
| 25 | +<div class="example-block"> |
| 26 | +<p><strong>Input:</strong> <span class="example-io">nums = [20,20,10,30,30,30]</span></p> |
| 27 | + |
| 28 | +<p><strong>Output:</strong> <span class="example-io">20</span></p> |
| 29 | + |
| 30 | +<p><strong>Explanation:</strong></p> |
| 31 | + |
| 32 | +<ul> |
| 33 | + <li>20 appears twice.</li> |
| 34 | + <li>10 appears once.</li> |
| 35 | + <li>30 appears 3 times.</li> |
| 36 | + <li>The frequency of 20, 10, and 30 are unique. The first element that has unique frequency is 20.</li> |
| 37 | +</ul> |
| 38 | +</div> |
| 39 | + |
| 40 | +<p><strong class="example">Example 3:</strong></p> |
| 41 | + |
| 42 | +<div class="example-block"> |
| 43 | +<p><strong>Input:</strong> <span class="example-io">nums = [10,10,20,20]</span></p> |
| 44 | + |
| 45 | +<p><strong>Output:</strong> <span class="example-io">-1</span></p> |
| 46 | + |
| 47 | +<p><strong>Explanation:</strong></p> |
| 48 | + |
| 49 | +<ul> |
| 50 | + <li>10 appears twice.</li> |
| 51 | + <li>20 appears twice.</li> |
| 52 | + <li>No element has a unique frequency.</li> |
| 53 | +</ul> |
| 54 | +</div> |
| 55 | + |
| 56 | +<p> </p> |
| 57 | +<p><strong>Constraints:</strong></p> |
| 58 | + |
| 59 | +<ul> |
| 60 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 61 | + <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> |
| 62 | +</ul> |
0 commit comments