File tree 2 files changed +27
-0
lines changed 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 82
82
134|[ Gas Station] ( ./0134-gas-station.js ) |Medium|
83
83
135|[ Candy] ( ./0135-candy.js ) |Hard|
84
84
136|[ Single Number] ( ./0136-single-number.js ) |Easy|
85
+ 137|[ Single Number II] ( ./0137-single-number-ii.js ) |Medium|
85
86
141|[ Linked List Cycle] ( ./0141-linked-list-cycle.js ) |Easy|
86
87
142|[ Linked List Cycle II] ( ./0142-linked-list-cycle-ii.js ) |Medium|
87
88
143|[ Reorder List] ( ./0143-reorder-list.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 137. Single Number II
3
+ * https://leetcode.com/problems/single-number-ii/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array nums where every element appears three times except for one, which appears
7
+ * exactly once. Find the single element and return it.
8
+ *
9
+ * You must implement a solution with a linear runtime complexity and use only constant extra space.
10
+ */
11
+
12
+ /**
13
+ * @param {number[] } nums
14
+ * @return {number }
15
+ */
16
+ var singleNumber = function ( nums ) {
17
+ let a = 0 , b = 0 ;
18
+
19
+ nums . forEach ( c => {
20
+ const offset = ( ~ a & b & c ) | ( a & ~ b & ~ c ) ;
21
+ b = ( ~ a & ~ b & c ) | ( ~ a & b & ~ c ) ;
22
+ a = offset ;
23
+ } ) ;
24
+
25
+ return a | b ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments