java.lang.Object
g2101_2200.s2150_find_all_lonely_numbers_in_the_array.Solution

public class Solution extends Object
2150 - Find All Lonely Numbers in the Array.<p>Medium</p> <p>You are given an integer array <code>nums</code>. A number <code>x</code> is <strong>lonely</strong> when it appears only <strong>once</strong> , and no <strong>adjacent</strong> numbers (i.e. <code>x + 1</code> and <code>x - 1)</code> appear in the array.</p> <p>Return <em><strong>all</strong> lonely numbers in</em> <code>nums</code>. You may return the answer in <strong>any order</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [10,6,5,8]</p> <p><strong>Output:</strong> [10,8]</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.</p> </li> <li> <p>8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.</p> </li> <li> <p>5 is not a lonely number since 6 appears in nums and vice versa.</p> </li> </ul> <p>Hence, the lonely numbers in nums are [10, 8].</p> <p>Note that [8, 10] may also be returned.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,3,5,3]</p> <p><strong>Output:</strong> [1,5]</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.</p> </li> <li> <p>5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.</p> </li> <li> <p>3 is not a lonely number since it appears twice.</p> </li> </ul> <p>Hence, the lonely numbers in nums are [1, 5].</p> <p>Note that [5, 1] may also be returned.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>0 <= nums[i] <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findLonely

      public List<Integer> findLonely(int[] nums)