Skip to content

Commit 94e2009

Browse files
authored
Add files via upload
1 parent 77a90d8 commit 94e2009

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int findMaxK(vector<int>& nums) {
4+
sort(nums.begin(), nums.end());
5+
int l = 0;
6+
int r = nums.size() - 1;
7+
while (l < r) {
8+
if (nums[l] >= 0 || nums[r] <= 0) {
9+
return -1;
10+
}
11+
if (-nums[l] == nums[r]) {
12+
return nums[r];
13+
}
14+
else if (-nums[l] > nums[r]) {
15+
++l;
16+
}
17+
else{
18+
--r;
19+
}
20+
}
21+
return -1;
22+
}
23+
};

0 commit comments

Comments
 (0)