2441. Largest Positive Integer That Exists With Its Negative
On This Page
class Solution:
def findMaxK(self, nums: List[int]) -> int:
nums.sort()
p1 = 0
p2 = len(nums)-1
while p1 < p2:
l = nums[p1]
r = nums[p2]
ssum = l + r
if ssum == 0:
return r
if ssum < 0:
p1 += 1
else:
p2 -= 1
return -1
class Solution:
def findMaxK(self, nums: List[int]) -> int:
s = set(nums)
return max((x for x in s if -x in s), default=-1)