Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab77bf6

Browse files
committed
Add solution #2441
1 parentcd8ab2b commitab77bf6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-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,950 LeetCode solutions in JavaScript
1+
#1,951 LeetCode solutions in JavaScript
22

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

@@ -1842,6 +1842,7 @@
18421842
2438|[Range Product Queries of Powers](./solutions/2438-range-product-queries-of-powers.js)|Medium|
18431843
2439|[Minimize Maximum of Array](./solutions/2439-minimize-maximum-of-array.js)|Medium|
18441844
2440|[Create Components With Same Value](./solutions/2440-create-components-with-same-value.js)|Hard|
1845+
2441|[Largest Positive Integer That Exists With Its Negative](./solutions/2441-largest-positive-integer-that-exists-with-its-negative.js)|Easy|
18451846
2444|[Count Subarrays With Fixed Bounds](./solutions/2444-count-subarrays-with-fixed-bounds.js)|Hard|
18461847
2460|[Apply Operations to an Array](./solutions/2460-apply-operations-to-an-array.js)|Easy|
18471848
2462|[Total Cost to Hire K Workers](./solutions/2462-total-cost-to-hire-k-workers.js)|Medium|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 2441. Largest Positive Integer That Exists With Its Negative
3+
* https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer array nums that does not contain any zeros, find the largest positive
7+
* integer k such that -k also exists in the array.
8+
*
9+
* Return the positive integer k. If there is no such integer, return -1.
10+
*/
11+
12+
/**
13+
*@param {number[]} nums
14+
*@return {number}
15+
*/
16+
varfindMaxK=function(nums){
17+
constset=newSet();
18+
letresult=-1;
19+
20+
for(constnumofnums){
21+
if(set.has(-num)){
22+
result=Math.max(result,Math.abs(num));
23+
}
24+
set.add(num);
25+
}
26+
27+
returnresult;
28+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp