Skip to content

Commit 14c045d

Browse files
committed
Add solution #961
1 parent 3e52a0b commit 14c045d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,393 LeetCode solutions in JavaScript
1+
# 1,394 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -773,6 +773,7 @@
773773
958|[Check Completeness of a Binary Tree](./solutions/0958-check-completeness-of-a-binary-tree.js)|Medium|
774774
959|[Regions Cut By Slashes](./solutions/0959-regions-cut-by-slashes.js)|Medium|
775775
960|[Delete Columns to Make Sorted III](./solutions/0960-delete-columns-to-make-sorted-iii.js)|Hard|
776+
961|[N-Repeated Element in Size 2N Array](./solutions/0961-n-repeated-element-in-size-2n-array.js)|Easy|
776777
962|[Maximum Width Ramp](./solutions/0962-maximum-width-ramp.js)|Medium|
777778
963|[Minimum Area Rectangle II](./solutions/0963-minimum-area-rectangle-ii.js)|Medium|
778779
964|[Least Operators to Express Number](./solutions/0964-least-operators-to-express-number.js)|Hard|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 961. N-Repeated Element in Size 2N Array
3+
* https://leetcode.com/problems/n-repeated-element-in-size-2n-array/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums with the following properties:
7+
* - nums.length == 2 * n.
8+
* - nums contains n + 1 unique elements.
9+
* - Exactly one element of nums is repeated n times.
10+
*
11+
* Return the element that is repeated n times.
12+
*/
13+
14+
/**
15+
* @param {number[]} nums
16+
* @return {number}
17+
*/
18+
var repeatedNTimes = function(nums) {
19+
const map = {};
20+
for (let i = 0; i < nums.length; i++) {
21+
if (!map[nums[i]]) map[nums[i]] = 1;
22+
else return nums[i];
23+
}
24+
};

0 commit comments

Comments
 (0)