File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,778 LeetCode solutions in JavaScript
1
+ # 1,779 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1647
1647
2147|[ Number of Ways to Divide a Long Corridor] ( ./solutions/2147-number-of-ways-to-divide-a-long-corridor.js ) |Hard|
1648
1648
2148|[ Count Elements With Strictly Smaller and Greater Elements] ( ./solutions/2148-count-elements-with-strictly-smaller-and-greater-elements.js ) |Easy|
1649
1649
2149|[ Rearrange Array Elements by Sign] ( ./solutions/2149-rearrange-array-elements-by-sign.js ) |Medium|
1650
+ 2150|[ Find All Lonely Numbers in the Array] ( ./solutions/2150-find-all-lonely-numbers-in-the-array.js ) |Medium|
1650
1651
2154|[ Keep Multiplying Found Values by Two] ( ./solutions/2154-keep-multiplying-found-values-by-two.js ) |Easy|
1651
1652
2161|[ Partition Array According to Given Pivot] ( ./solutions/2161-partition-array-according-to-given-pivot.js ) |Medium|
1652
1653
2176|[ Count Equal and Divisible Pairs in an Array] ( ./solutions/2176-count-equal-and-divisible-pairs-in-an-array.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2150. Find All Lonely Numbers in the Array
3
+ * https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array nums. A number x is lonely when it appears only once, and
7
+ * no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
8
+ *
9
+ * Return all lonely numbers in nums. You may return the answer in any order.
10
+ */
11
+
12
+ /**
13
+ * @param {number[] } nums
14
+ * @return {number[] }
15
+ */
16
+ var findLonely = function ( nums ) {
17
+ const map = new Map ( ) ;
18
+
19
+ for ( const num of nums ) {
20
+ map . set ( num , ( map . get ( num ) || 0 ) + 1 ) ;
21
+ }
22
+
23
+ const result = [ ] ;
24
+ for ( const [ num , count ] of map ) {
25
+ if ( count === 1 && ! map . has ( num - 1 ) && ! map . has ( num + 1 ) ) {
26
+ result . push ( num ) ;
27
+ }
28
+ }
29
+
30
+ return result ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments