Skip to content

Commit d29890a

Browse files
committed
2150. Find All Lonely Numbers in the Array: RETRY
1 parent fd95155 commit d29890a

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,3 +1625,4 @@ mod s2146_k_highest_ranked_items_within_a_price_range;
16251625
mod s2147_number_of_ways_to_divide_a_long_corridor;
16261626
mod s2148_count_elements_with_strictly_smaller_and_greater_elements;
16271627
mod s2149_rearrange_array_elements_by_sign;
1628+
mod s2150_find_all_lonely_numbers_in_the_array;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* [2150] Find All Lonely Numbers in the Array
3+
*
4+
* You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
5+
* Return all lonely numbers in nums. You may return the answer in any order.
6+
*
7+
* Example 1:
8+
*
9+
* Input: nums = [10,6,5,8]
10+
* Output: [10,8]
11+
* Explanation:
12+
* - 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.
13+
* - 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.
14+
* - 5 is not a lonely number since 6 appears in nums and vice versa.
15+
* Hence, the lonely numbers in nums are [10, 8].
16+
* Note that [8, 10] may also be returned.
17+
*
18+
* Example 2:
19+
*
20+
* Input: nums = [1,3,5,3]
21+
* Output: [1,5]
22+
* Explanation:
23+
* - 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.
24+
* - 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.
25+
* - 3 is not a lonely number since it appears twice.
26+
* Hence, the lonely numbers in nums are [1, 5].
27+
* Note that [5, 1] may also be returned.
28+
*
29+
*
30+
* Constraints:
31+
*
32+
* 1 <= nums.length <= 10^5
33+
* 0 <= nums[i] <= 10^6
34+
*
35+
*/
36+
pub struct Solution {}
37+
38+
// problem: https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/
39+
// discuss: https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/discuss/?currentPage=1&orderBy=most_votes&query=
40+
41+
// submission codes start here
42+
43+
impl Solution {
44+
pub fn find_lonely(nums: Vec<i32>) -> Vec<i32> {
45+
vec![]
46+
}
47+
}
48+
49+
// submission codes end
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use super::*;
54+
55+
#[test]
56+
#[ignore]
57+
fn test_2150_example_1() {
58+
let nums = vec![10, 6, 5, 8];
59+
60+
let result = vec![10, 8];
61+
62+
assert_eq!(Solution::find_lonely(nums), result);
63+
}
64+
65+
#[test]
66+
#[ignore]
67+
fn test_2150_example_2() {
68+
let nums = vec![1, 3, 5, 3];
69+
70+
let result = vec![1, 5];
71+
72+
assert_eq!(Solution::find_lonely(nums), result);
73+
}
74+
}

0 commit comments

Comments
 (0)