Skip to content

Commit f2584f1

Browse files
committed
Add solution #260
1 parent 8d6b849 commit f2584f1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
237|[Delete Node in a Linked List](./0237-delete-node-in-a-linked-list.js)|Easy|
206206
238|[Product of Array Except Self](./0238-product-of-array-except-self.js)|Medium|
207207
242|[Valid Anagram](./0242-valid-anagram.js)|Easy|
208+
260|[Single Number III](./0260-single-number-iii.js)|Medium|
208209
263|[Ugly Number](./0263-ugly-number.js)|Easy|
209210
264|[Ugly Number II](./0264-ugly-number-ii.js)|Medium|
210211
268|[Missing Number](./0268-missing-number.js)|Easy|

solutions/0260-single-number-iii.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 260. Single Number III
3+
* https://leetcode.com/problems/single-number-iii/
4+
* Difficulty: Medium
5+
*
6+
* Given an integer array nums, in which exactly two elements appear only once and all
7+
* the other elements appear exactly twice. Find the two elements that appear only once.
8+
* You can return the answer in any order.
9+
*/
10+
11+
/**
12+
* @param {number[]} nums
13+
* @return {number[]}
14+
*/
15+
var singleNumber = function(nums) {
16+
const set = new Set();
17+
nums.forEach(n => set.has(n) ? set.delete(n) : set.add(n));
18+
return Array.from(set);
19+
};

0 commit comments

Comments
 (0)