Skip to content

Commit d042d85

Browse files
authored
Create 1133-largest-unique-number.js
1 parent fed0822 commit d042d85

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1133-largest-unique-number.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const largestUniqueNumber = function(nums) {
6+
const hash = {}
7+
for(let e of nums) {
8+
hash[e] = (hash[e] || 0) + 1
9+
}
10+
let res = -Infinity
11+
Object.keys(hash).forEach(k => {
12+
if(hash[k] === 1) {
13+
if(+k > res) {
14+
res = +k
15+
}
16+
}
17+
})
18+
return res === -Infinity ? -1 : res
19+
};

0 commit comments

Comments
 (0)