LeetCode solutions

2524. Largest Positive Integer That Exists With Its Negative

My accepted Python solution to LeetCode problem 2524, Largest Positive Integer That Exists With Its Negative, running in 10ms.

  • Difficulty: Easy
  • Python
  • Runtime 10ms
  • Memory 12.7MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 10ms, memory 12.7MB, accepted 2025-12-24.

python
class Solution(object):
    def findMaxK(self, nums):
        num_set = set(nums)
        result = -1
        for num in nums:
            if num > 0 and -num in num_set:
                result = max(result, num)
        return result

Source