Solved! Leetcode 2441. Largest Positive Integer That Exists With Its Negative

Description: Largest Positive Integer That Exists With Its Negative

Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.

Return the positive integer k. If there is no such integer, return -1.

Example 1

Example 2

Example 3

Constraints

  • 1 <= nums.length <= 1000
  • -1000 <= nums[i] <= 1000
  • nums[i] != 0

Solution

Time Complexity

O(1), fixed length array

Space Complexity

O(1)

Rate this post

Leave a Reply